VM Powershell lost VM IPaddress after export

Can some expert help me? I need vm IP address in excel.


I run the command, then get IP address in Powershell  Consle

Get-VMGuest -vm CCC | Select-Object -Property VmName,HostName,OSFullName,IPAddress,State .

VmName : CCC
HostName : CCC
OSFullName : Microsoft Windows Server 2016 or later (64-bit)
IPAddress : {, fe80::e47f:d53d:c1c1:87b8}
State : Running

But I run the command

Get-VMGuest -vm CCC | Select-Object -Property VmName,HostName,OSFullName,IPAddress,State |  Export-Excel -Path c:\ser.xlsx | start excel C:\ser.xlsx

I can not get IP address,only got system.string[]

CCCCCCMicrosoft Windows Server 2016 or later (64-bit)System.String[]Running
0 Kudos
1 Reply

That is basically an EXport-Excel issue.
The IPAddress property is an Array, and Export-Excel doesn't know how to handle that.
The cmdlet indicates that by showing the type of that property, in this case, an array of strings.

The PS output engine does know how to handle such an array.

One way to fix that is by converting that property to a single string value.

You can do that with a calculated property.

@{N='IPAddress';E={$_.IPAddress -join '|'}}

Blog:  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos