2016-12-27 46 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