I have found the Connect-VIserver effects the output format of my custom objects.For example
Without Connect-VIServer
$output=@() $hosts = @("host1","host2") $VMs = @("VM1","VM2") $obj1 = New-Object psobject $obj1 | Add-Member NoteProperty -Name "Host" $hosts[0] $obj1 | Add-Member NoteProperty -Name "VM" $VMs[0] $obj2 = New-Object psobject $obj2 | Add-Member NoteProperty -Name "Host" $hosts[1] $obj2 | Add-Member NoteProperty -Name "VM" $VMs[1] $output = $output + ($obj1, $obj2) $output
Provides this output:
With Connect-VIServer
Connect-VIServer localhost -user $VCuser -password $VCpass $output=@() $hosts = @("host1","host2") $VMs = @("VM1","VM2") $obj1 = New-Object psobject $obj1 | Add-Member NoteProperty -Name "Host" $hosts[0] $obj1 | Add-Member NoteProperty -Name "VM" $VMs[0] $obj2 = New-Object psobject $obj2 | Add-Member NoteProperty -Name "Host" $hosts[1] $obj2 | Add-Member NoteProperty -Name "VM" $VMs[1] $output = $output + ($obj1, $obj2) $output
Output looks like
I cant find a way to correct this and was hoping someone may have a solution?
Thanks,
Luke
For the explanantion of what you are seeing you have to understand how PowerShell handles objects in the output stream.
A very good explanation can be found in How PowerShell Formatting and Outputting REALLY works.
In short:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
For the explanantion of what you are seeing you have to understand how PowerShell handles objects in the output stream.
A very good explanation can be found in How PowerShell Formatting and Outputting REALLY works.
In short:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD, that help me get it fixed. I used Out-Default to return the formatting to default.
Connect-VIServer localhost -user $VCuser -password $VCpass$output=@()$hosts = @("host1","host2")$VMs = @("VM1","VM2")$obj1 = New-Object psobject$obj1 | Add-Member NoteProperty -Name "Host" $hosts[0]$obj1 | Add-Member NoteProperty -Name "SVA" $VMs[0]$obj2 = New-Object psobject$obj2 | Add-Member NoteProperty -Name "Host" $hosts[1]$obj2 | Add-Member NoteProperty -Name "SVA" $VMs[1]$output = $output + ($obj1, $obj2)$output | Out-Default