AlbertWT
Virtuoso
Virtuoso

How to combine the result of two PowerShell script into one script ?

Jump to solution

Hi,

I've got the two lines of PowerShell script that I use to get some ESXi server information, so I wonder how do I combine these two into the single result in a CSV file ?

Get-VMHost | Get-VMHostNetwork | Select Hostname, DomainName, Name, VMHost, DNSAddress | ft -AutoSize

Get-VMHost | Select Name, Version, Manufacturer, Model | ft -AutoSize

Thanks in advance,

/* Any kind of comment or input would be greatly appreciated */
1 Solution

Accepted Solutions
kwhornlcs
Enthusiast
Enthusiast

Something like this should work (Note: for some reason PS will throw a syntax error on this one if you don't remove the extra line breaks when you copy and paste from the post):

Get-VMHost | Get-VMHostNetwork |`

Select `

    @{N='Host';E={$_.VMHost.Name}},`

    @{N='Version';E={$_.VMHost.Version}},`

    @{N='Manufacturer';E={$_.VMHost.Manufacturer}},`

    @{N='Model';E={$_.VMHost.Model}}, DomainName, Name,`

    @{N="DNSAddresses";E={[string]::join(";",($_.DNSAddress))}}|`

Export-Csv c:\vmtntest.csv -NoTypeInformation -UseCulture

View solution in original post

2 Replies
kwhornlcs
Enthusiast
Enthusiast

Something like this should work (Note: for some reason PS will throw a syntax error on this one if you don't remove the extra line breaks when you copy and paste from the post):

Get-VMHost | Get-VMHostNetwork |`

Select `

    @{N='Host';E={$_.VMHost.Name}},`

    @{N='Version';E={$_.VMHost.Version}},`

    @{N='Manufacturer';E={$_.VMHost.Manufacturer}},`

    @{N='Model';E={$_.VMHost.Model}}, DomainName, Name,`

    @{N="DNSAddresses";E={[string]::join(";",($_.DNSAddress))}}|`

Export-Csv c:\vmtntest.csv -NoTypeInformation -UseCulture

AlbertWT
Virtuoso
Virtuoso

many thanks, kwhornlcs, it is working as expected and I learn something new too from your script.

/* Any kind of comment or input would be greatly appreciated */
0 Kudos