VMware Cloud Community
DevKhurana
Enthusiast
Enthusiast
Jump to solution

Get-VM details

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'}}}

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Then try like this

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($_.PowerState -eq 'PoweredOff' -or -not (Get-Cluster -VM $_).HAEnabled){'NA'}

        else{$_.ExtensionData.Runtime.DasVmProtection.DasProtected}}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

Something like this?

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($_.PowerState -eq 'PoweredOff' -or -not (Get-Cluster -VM $_)){'NA'}

        else{$_.ExtensionData.Runtime.DasVmProtection.DasProtected}}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
DevKhurana
Enthusiast
Enthusiast
Jump to solution

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)

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then try like this

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($_.PowerState -eq 'PoweredOff' -or -not (Get-Cluster -VM $_).HAEnabled){'NA'}

        else{$_.ExtensionData.Runtime.DasVmProtection.DasProtected}}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
DevKhurana
Enthusiast
Enthusiast
Jump to solution

Thanks LucD, It's same as I want

0 Kudos
DevKhurana
Enthusiast
Enthusiast
Jump to solution

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}}}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

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($_.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

0 Kudos
DevKhurana
Enthusiast
Enthusiast
Jump to solution

Thanks

0 Kudos