2016-12-27 49 views
0

我能夠通過使用以下代碼獲得可用空間作爲ouptut。當數據存儲中的空閒存儲空間不足時,使用PowerCLI在VMWare中創建票證

$body +=echo "------------Free space on Datastore.--------------"`r`n""`r`n"" 
$body +=get-datastore -name *datastore1* | sort Name | ForEach-Object { 
    $output=New-Object -TypeName PSObject -Property @{ 
     Freespace = "$([math]::Round($_.FreeSpaceGB, 2)) GB" 
     Datastore_Name = $_.Name 
     }  
    } 
    Write-Output $output 

是否有可能提高一票,如果自由空間小於2 GB?如果是這樣,我應該如何更改我的代碼?

回答

0

編輯:

if (get-datastore | where {$_.FreeSpaceGB -lt 2}){"dosomething"} 

foreach ($ds in (get-datastore | where {$_.FreeSpaceGB -lt 2})){"dosomething"} 
+0

請4位正確格式縮進代碼。也值得解釋代碼的作用。 – Bugs