Aman Dhally
Aman Dhally

Reputation: 75

How to deal with System.String[]

I am using the below script line to get the IP information of system and then exporting in to a HTML file. But when I export the file the Most of the values of below command comes in System.String[], and I searched the net but not able to find how to deal with this.

Get-WmiObject win32_NetworkAdapterConfiguration | select Description,DHCPServer,IpAddress,IpSubnet,DefaultIPgateway,DNSServerSearchOrder,WinsPrimaryServer,WINSSecindaryServer | ConvertTo-Html > d:\aman.html

When I check the Properties in IPADDRESS using WMIEXPLORER tool, these are arrays and I don't know how to manipulate them.

And I want the output in table format so that it can easily fit in to my Reports.

Upvotes: 0

Views: 23383

Answers (1)

Rynant
Rynant

Reputation: 24343

You could use a calculated field in the Select-Object statement and join the array.

Here, IPAddress is joined with a semicolon:

EDIT: Updated with remaning string array properties, and added a space after semicolon to allow the string to wrap in the displayed HTML

Get-WmiObject Win32_NetworkAdapterConfiguration| 
    Select-Object Description, DHCPServer, 
        @{Name='IpAddress';Expression={$_.IpAddress -join '; '}}, 
        @{Name='IpSubnet';Expression={$_.IpSubnet -join '; '}}, 
        @{Name='DefaultIPgateway';Expression={$_.DefaultIPgateway -join '; '}}, 
        @{Name='DNSServerSearchOrder';Expression={$_.DNSServerSearchOrder -join '; '}}, 
        WinsPrimaryServer, WINSSecindaryServer|
    ConvertTo-Html > .\temp.htm

Upvotes: 2

Related Questions