Label expression and changing expression when it’s going to be negative


Get-Datacenter -Name “xxx Datacenter” | Get-Datastore | Select-Object @{Label=”DataStore Name”;Expression={$_.Name}},@{Label=”GB Left”;Expression={[Math]::Round($_.FreeSpaceMB/1024,2)}},@{Label=”Capacity GB”;Expression={[Math]::Round($_.CapacityMB/1024,2)}},@{Label=”Free %”;Expression={[Math]::Round($_.FreeSpaceMB/$_.CapacityMB,3)*100}},@{Label=”New VMs”;Expression={[Math]::Floor(“{0:0.00;’0′}” -f (($_.FreeSpaceMB – 30000)/20480)) }} | ConvertTo-Html -Head $head -Body $header | Out-File “d:\bbb.html”

“{0:0.00;’0′}” -f (($_.FreeSpaceMB – 30000)/20480) -> will put 0 when the value will be negative, if positive if will leave the value like it is.

More about formatting:

http://msdn.microsoft.com/en-us/library/0c899ak8%28v=vs.71%29.aspx

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s