VMware Cloud Community
Vel_VMware
Enthusiast
Enthusiast

If condition not working

Hi,

I am trying to create one small script to check datastore utilization percent, but if condition is not working. Can any one help me on this.

Connect-VIServer -Server VC001

$size = Get-Datastore -Name Datastore001 | Select-Object name, @{name="CapacityGB";Expression={[math]::Round($_.capacitygb,2)}}, @{name="FreeSpaceGB";Expression={[math]::Round($_.freespacegb,2)}}, @{name="PercentFree";Expression={[math]::Round(($_.freespacegb / $_.capacitygb * 100),2)}}

If(percentFree -gt 50)

{

'Datastore freespace is morethan 50%'

}

else

{

'Datastore  freespace is lessthan 50%'

}

Thanks in advance

0 Kudos
1 Reply
jpsider
Expert
Expert

Should be a quick change for you:

If($size.percentFree -gt 50) { 'Datastore freespace is morethan 50%' } else { 'Datastore  freespace is lessthan 50%' }

0 Kudos