The output you get from a command in a script depends on the output from the previous commands. You can pipe the output from the commands you don't want to see to | Out-Null.
Connect-VIServer -Server esx-101.mylab.net -User root -Password mypassword | Out-Null
Start-VM ServerVM1 | Out-Null
Start-VM ServerVM2 | Out-Null
Disconnect-VIServer -Confirm:$false | Out-Null
The reason you are seeing what you are seeing is due to the reason the 'formatter' works in PowerShell.
There are some rules when the formatter is dealing with multiple, non-primitive objects in the pipeline.
In this case, the first non-primitive object is the result from your Connect-VIServer, for which there is a type declaration in PowerCLI.
This results in a Format-Custom type of format, which will lock in all subsequent non-primitive objects in Format-List (and not the Format-Table you get when you just do Get-VM).
Instead of hiding output, you can 'reset' the formatter, by piping each object to the Out-Default cmdlet.
This will force the formatter to handle each non-primitive object as if it is the first one.Connect-VIServer -Server esx-101.mylab.net -User root -Password mypassword | Out-Default
Start-VM ServerVM1 | Out-Default
Start-VM ServerVM2 | Out-Default
Get-VM | Out-Default
Disconnect-VIServer -Confirm:$false | Out-DefaultBlog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz1 person found this helpful