![](/img/trans.png)
[英]How to check particular VMware VM is not currently running in the task using PowerShell?
[英]How to get vmware vm list which has more than 25% of used space of the particular datastore using powershell?
我需要獲取虛擬機列表,該列表具有特定數據存儲區中已使用空間的25%。
$vmdatastore = Get-Datastore "XXXXX-LUN001" | select Name, @{N = Capacity";E={[math]::Round($_.ExtensionData.Summary.Capacity / 1GB, 2)}},@{N="FreeSpace";E={[math]::Round($_.ExtensionData.Summary.FreeSpace/1GB, 2)}}, @{N="PercentageFreeSpace";E={[math]::Round(($_.FreeSpaceGB) /($_.CapacityGB) * 100, 2)}}
$vmlists=Get-Datastore "XXXXX-LUN001" | Get-VM | Select name, @{N="DSName";E={$vmdatastore.Name}},usedspacegb, provisionedspacegb
幫助我獲取具有特定數據存儲中25%使用空間的虛擬機列表。
不太確定,這是否是您想要的,但是如果您想要一個VM列表,這些VM在一起至少占數據存儲容量的25%,則此方法可能會有所幫助:
$ds = Get-Datastore "XXXXX-LUN001"
$dsVMs = Get-VM -Datastore $ds
$vmUsedSpace = 0
$vmMigrationCandidates = @()
$dsCapacityThreshold = $ds.CapacityGB / 4
while ($vmUsedSpace -le $dsCapacityThreshold -and $dsVMs.Count -gt 0)
{
$vm,$dsVMs = $dsVMs
$vmUsedSpace += $vm.UsedSpaceGB
$vmMigrationCandidates += $vm
}
$vmMigrationCandidates
將保存一個VM列表,這些VM在一起至少使用了數據存儲總容量的25%。 (或者,如果此數據存儲上的所有虛擬機加在一起沒有達到閾值,則為該虛擬機。)
如果您要遷移幾個“大” vms而不是許多“小” vms,則仍然需要確定。 還應考慮到可能必須考慮DRS主機或虛擬機關聯性規則。
$gt25 = $vmdatastore | ?{$_.PercentageFreeSpace -gt 25}
Get-Datastore -name $gt25 | Get-VM
評論后...怎么樣
$vmdatastore = Get-Datastore "xxxxyourdatastorexxx" | select Name, @{N =
"Capacity";E={[math]::Round($_.ExtensionData.Summ
ary.Capacity / 1GB, 2)}}, @{N = "QuarterOfThat";E=
{[math]::Round($_.ExtensionData.Summary.Capacity / 1GB / 4, 2)}}
$vmlist = Get-Datastore ABN_NP_CORE2 | get-vm | ? {$_.usedspaceGB -gt
$vmdatastore.QuarterOfThat}
$vmlist.usedspaceGB
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.