Could some one help me please, in last statement, I want something like this, If VM state is poweroff or VM is not in a HA enabled cluster then outcome 'N/A' otherwise value of ($_.ExtensionData.Runtime.DasVmProtection.DasProtected)
Get-VM |
Select Name,PowerState,VMHost,
@{N="IP Address";E={@($_.guest.IPAddress -join ',')}},
@{N="GuestOS";E={$_.Guest.OSFullName}},
@{N="VMware Tools Running Status";E={$_.ExtensionData.Guest.ToolsRunningStatus}},
@{N="Provisioned Space"; E={[math]::round($_.ProvisionedSpaceGB,2)}},
@{N='HA Protected';E={if($_.ExtensionData.Runtime.DasVmProtection.DasProtected){'Yes'}else{'No'}}}
Then try like this
Select Name,PowerState,VMHost,
@{N="IP Address";E={@($_.guest.IPAddress -join ',')}},
@{N="GuestOS";E={$_.Guest.OSFullName}},
@{N="VMware Tools Running Status";E={$_.ExtensionData.Guest.ToolsRunningStatus}},
@{N="Provisioned Space"; E={[math]::round($_.ProvisionedSpaceGB,2)}},
@{N='HA Protected';E={
if($_.PowerState -eq 'PoweredOff' -or -not (Get-Cluster -VM $_).HAEnabled){'NA'}
else{$_.ExtensionData.Runtime.DasVmProtection.DasProtected}}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Something like this?
Select Name,PowerState,VMHost,
@{N="IP Address";E={@($_.guest.IPAddress -join ',')}},
@{N="GuestOS";E={$_.Guest.OSFullName}},
@{N="VMware Tools Running Status";E={$_.ExtensionData.Guest.ToolsRunningStatus}},
@{N="Provisioned Space"; E={[math]::round($_.ProvisionedSpaceGB,2)}},
@{N='HA Protected';E={
if($_.PowerState -eq 'PoweredOff' -or -not (Get-Cluster -VM $_)){'NA'}
else{$_.ExtensionData.Runtime.DasVmProtection.DasProtected}}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD, This is somehow correct but not exactly I want, If VM state is poweroff or VM is not in a HA enabled cluster (It could be in a cluster but HA is not enabled on that cluster) then outcome 'N/A' otherwise value of ($_.ExtensionData.Runtime.DasVmProtection.DasProtected)
Then try like this
Select Name,PowerState,VMHost,
@{N="IP Address";E={@($_.guest.IPAddress -join ',')}},
@{N="GuestOS";E={$_.Guest.OSFullName}},
@{N="VMware Tools Running Status";E={$_.ExtensionData.Guest.ToolsRunningStatus}},
@{N="Provisioned Space"; E={[math]::round($_.ProvisionedSpaceGB,2)}},
@{N='HA Protected';E={
if($_.PowerState -eq 'PoweredOff' -or -not (Get-Cluster -VM $_).HAEnabled){'NA'}
else{$_.ExtensionData.Runtime.DasVmProtection.DasProtected}}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD, It's same as I want
A little more help please, in else statement also if value is True then outcome 'Protected' and if value is False then outcome 'Not protected', can it be possible
@{N='HA Protected';E={
if($_.PowerState -eq 'PoweredOff' -or -not (Get-Cluster -VM $_).HAEnabled){'NA'}
else{$_.ExtensionData.Runtime.DasVmProtection.DasProtected}}}
Try like this
Select Name,PowerState,VMHost,
@{N="IP Address";E={@($_.guest.IPAddress -join ',')}},
@{N="GuestOS";E={$_.Guest.OSFullName}},
@{N="VMware Tools Running Status";E={$_.ExtensionData.Guest.ToolsRunningStatus}},
@{N="Provisioned Space"; E={[math]::round($_.ProvisionedSpaceGB,2)}},
@{N='HA Protected';E={
if($_.PowerState -eq 'PoweredOff' -or -not (Get-Cluster -VM $_).HAEnabled){'NA'}
else{
if($_.ExtensionData.Runtime.DasVmProtection.DasProtected){'Protected'}
else{'Not protected'}}}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks