If from the PowerShell I type Get-VM the VMs appear in a formated table.
When I have a PowerShell script that called the same command the details of the VMs are presented sequentially.
Can someone please explain this? Is there some form of default view when commands are executed in the power shell.
I have a script from which I want to list the names of all the VMs in a table e.g.
Name VMHost
VM1 host1
VM2 host2
When I execute "Get-VM | Select Name, VMHost " in my script I get
Name: VM1
Host: host1
Nmae: VM2
Host: host2
As I have a large number of VMs this becomes very unreadable.
Any help would be gratefully appreciated.
That could be due to the linelength PS thinks you have and the length of the properties.
Try something like this
Get-VM | Select Name, VMHost | ft -Autosize
Check what the current linelength is with
$Host.ui.rawui.WindowSize.width
You can check what the maxima are with
$host.ui.rawui.MaxWindowSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for this.
I can use fl and ft to switch the format from list to table using the power shell command line. e.g.
Get-VM | Select Name, VMHost | ft and
Get-VM | Select Name, VMHost | fl
When I enter either of these lines in to a script and run it (including ft -AutoSize) I get the following error:
"Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not
in the correct sequence. This is likely caused by a user-specified "format-table" command which is conflicting with th
e default formatting.
+ CategoryInfo : InvalidData: (:) [out-lineoutput], InvalidOperationException
+ FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand
Having googled this I found the following post http://communities.vmware.com/message/1665165
This indicates it is a bug and can be fixed with the following
Get-VM | Select Name, VMHost | ft | out-default
Will try it now....
Fixed. Thanks for the help
That is indeed an annoying bug 😞
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference