VMware Cloud Community
BCDOC
Contributor
Contributor
Jump to solution

help needed stringing parameters together - powercli.

Hi,

I have this string that half works.

i am unable to sting together to get the .config and .guest and .guest.net all in one command string.

any suggestions.

> Get-VM -name "System1" | Sort | Get-View -Property @("Name", "Config.ChangeVersion", "guest.guestfullname", "Guest.hostname", "guest.ipaddress", "guest.gueststate", "guest.net.network") | Select -Property Name, @{N="ChangeVersion";E={$_.Config.ChangeVersion}}, @{N="Running OS";E={$_.Guest.GuestFullName}}, @{N="Hostname";E={$_.Guest.hostname}}, @{N="IP Address";E={$_.Guest.ipaddress}}, @{N="State";E={$_.Guest.gueststate}}, @{N="Network";E={$_.Guest.net.network}} | Format-Table -AutoSize

it should give me screen output of: but only give first three fields.

NameChangeVersion          Running OS                        Hostname IP Address State Network
-----------------          ----------                        -------- ---------- ----- -------

System1 2019-03-13T16:46:29.301502Z Microsoft Windows Server 2016 (64-bit)

goal to get

     name, changeVersion, guestfullname, hostname, ipaddress, gueststate, guest.net.network

thanks.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The problem is with the last property.

Since Guest.Net is an array, you not do Guest.Net Network.

But that is no issue do display the Network values in a calculated property with the -join operator

Get-VM -name "System1" |

sort |

Get-View -Property "Name", "Config.ChangeVersion", "guest.guestfullname", "Guest.hostname", "guest.ipaddress", "guest.gueststate", "guest.net" |

select -Property Name, @{N = "ChangeVersion"; E = { $_.Config.ChangeVersion } },

@{N = "Running OS"; E = { $_.Guest.GuestFullName } },

@{N = "Hostname"; E = { $_.Guest.hostname } },

@{N = "IP Address"; E = { $_.Guest.ipaddress } },

@{N = "State"; E = { $_.Guest.gueststate } },

@{N = "Network"; E = { $_.Guest.net.network -join '|' } } |

Format-Table -AutoSize


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

View solution in original post

0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

The problem is with the last property.

Since Guest.Net is an array, you not do Guest.Net Network.

But that is no issue do display the Network values in a calculated property with the -join operator

Get-VM -name "System1" |

sort |

Get-View -Property "Name", "Config.ChangeVersion", "guest.guestfullname", "Guest.hostname", "guest.ipaddress", "guest.gueststate", "guest.net" |

select -Property Name, @{N = "ChangeVersion"; E = { $_.Config.ChangeVersion } },

@{N = "Running OS"; E = { $_.Guest.GuestFullName } },

@{N = "Hostname"; E = { $_.Guest.hostname } },

@{N = "IP Address"; E = { $_.Guest.ipaddress } },

@{N = "State"; E = { $_.Guest.gueststate } },

@{N = "Network"; E = { $_.Guest.net.network -join '|' } } |

Format-Table -AutoSize


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

0 Kudos