当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 通过 PowerCLI 检查 VMFS 数据存储上的可用空间

作者:精品下载站 日期:2024-12-14 23:04:20 浏览:16 分类:玩电脑

通过 PowerCLI 检查 VMFS 数据存储上的可用空间


在本文中,我们将展示一个简单的 PowerCLI 脚本,用于检查 VMWare vSphere 数据存储上的可用空间量,并检测虚拟机精简虚拟磁盘(动态扩展)总大小超过数据存储总大小的精简配置数据存储。如果您的基础架构中有多个 VMWare 数据存储,则可以轻松使用此 PowerShell 脚本来监控可用空间量并检测存储过量使用的数据存储(所有 VM 的精简磁盘的空间要求大于 VMFS 数据存储上的可用空间)。您可以在创建虚拟机之前使用该脚本来分析已用空间的增长情况,以查找存在精简配置过度使用的数据存储等。

为了使 vSphere 基础架构正常工作,建议 VMWare VMFS 数据存储上至少有 5-10% 的可用空间。如果您使用快照(包括备份系统创建的快照),则至少需要有 10-15% 的可用空间。

要检查并显示 VMWare 数据存储上的可用空间量,您可以使用下面的 PowerShell 脚本(假设您的计算机上已安装 VMWare vSphere PowerCLI 模块):

# Import the PowerCLI module into your PowerShell session
Import-Module VMware.VimAutomation.Core -ErrorAction SilentlyContinue
# Connect to vCenter host
Connect-VIServer mun-vcsa1 -User admin
# Get the list of vCenter darastores
$datastores = Get-Datastore
$ErrorActionPreference = 'SilentlyContinue'
# loop through all available datastores
ForEach ($datastore in $datastores)
{
# Find the size of the committed space of all thin disks in a datastore (how much space it is required if all vmdk files will grow to the sizes specified in their settings)
$Provision = ([Math]::Round(($datastore.ExtensionData.Summary.Capacity - $datastore.ExtensionData.Summary.FreeSpace + $datastore.ExtensionData.Summary.Uncommitted)/1GB,0))
# Percentage of free space in the datastore
$PerFree = ([math]::Round(($datastore.FreeSpaceGB)/($datastore.CapacityGB)*100,2))
# Percentage of thin disk overcommitment
$PerOvercommit = ([math]::Round($Provision/($datastore.CapacityGB)*100,2))
# Add extra properties to the datastore object
$datastore | Add-Member -type NoteProperty -name PercentsFree -value $PerFree
$datastore | Add-Member -type NoteProperty -name CapacityGb_r -value ([Math]::Round(($datastore.ExtensionData.Summary.Capacity)/1GB,0))
$datastore | Add-Member -type NoteProperty -name FreeSpaceGb_r -value ([Math]::Round(($datastore.ExtensionData.Summary.FreeSpace)/1GB,0))
$datastore | Add-Member -type NoteProperty -name ProvisionedSpaceGb -value $Provision
$datastore | Add-Member -type NoteProperty -name PercentsOvercommit -value $PerOvercommit
}
# Display the resulting data on VMWare datastores and export the output to a CSV file
$datastores|select-object Name, Type, Datacenter,CapacityGb_r,FreeSpaceGb_r,PercentsFree,ProvisionedSpaceGb,PercentsOvercommit|sort PercentsFree| Export-Csv C:\Reports\VMWareVMFSDatastores.csv -NoTypeInformation

[玩转系统] 通过 PowerCLI 检查 VMFS 数据存储上的可用空间

如果您尝试使用 Connect-VIServer 连接到 vCenter 并看到以下错误:

Could not resolve the requested VC server.Additional Information: There was no endpoint listening at https://mun-vcsa1/sdk that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details

PowerCLI 可能会尝试通过代理连接到 VCSA。跑步

PowerCLIConfiguration

并检查是否

UseSystemProxy

返回。如果是,请使用以下命令禁用 PowerCLI 的系统代理:

Set-PowerCliConfiguration -proxypolicy noproxy

在我的示例中,您可以看到前 5 个 VMFS 数据存储的剩余可用空间不到 5%(绿色框)。某些数据存储上存在存储过量使用(数据存储中所有精简虚拟磁盘的总大小超过其大小)。如果您的虚拟 VM 磁盘开始增长到其设置中指定的最大大小,您的 VMFS/NFS/VVOL 存储上的空间可能会不足。 (使用厚磁盘运行虚拟机将照常工作,但您将无法启动新虚拟机,因为没有空间来创建 VSWAP 文件。)已提交空间大于总 LUN 大小的数据存储以黄色突出显示。

[玩转系统] 通过 PowerCLI 检查 VMFS 数据存储上的可用空间

此 PowerShell 脚本将帮助您快速找到可用空间不足的 VMWare 数据存储(您可以使用 Storage vMotion 从数据存储中迁移虚拟机)。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯