VMware Cloud Community
KroBaar
Contributor
Contributor

Obtaining snapshot from vSphere - different outputs

First, I appologize if I've posted this to the wrong community.  I have the VMware Infrastructure Toolkit for Windows installed and I'm trying to write some powershell scripts to generate a snapshot and one to list snapshots.  I have the script working, but I notice a difference in the output depending on how I launch the script and I'm not certain why, or if I can control that.

The following script is one I use to list snapshots:

# This script lists snapshot(s) for a virtual machine
# author 20.AUG.2010

param([string]$machine = "wkv")
$machine = $machine + "*"

Initialize-VIToolkitEnvironment.ps1

Connect-VIServer SRG11503.fully.qualified.domain.name

"" # Insert a blank line


get-vm $machine | get-snapshot | select name, description, powerstate

# End Script

This script can be launched from the command line (or shortcut) by issuing the following:

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -psc "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" -noe -c ". \"U:\my documents\Scripts\ListSnapshot.ps1\" "WKV15300""

The "WKV15300" at the end is the virtual machine name that I pass to the script that I want snapshots listed for.  When I run it like that, my output is not in row form like I expect it to be:

Name        : WKV15300_06_07_2010_Active
Description : Active snapshot
PowerState  : PoweredOn


Name        : WKV15300_06_07_2010_InActive
Description : InActive snapshot
PowerState  : PoweredOff


Name        : WKV15300-Current
Description : Testing
PowerState  : PoweredOn

With the same powershell window open, if I then edit the script and comment out the following line:

Connect-VIServer SRG11503.fully.qualified.domain.name

and then run the script again from that window like this:

&"U:\my documents\Scripts\ListSnapshot.ps1" "WKV15300"

The output I get is more in like a rows and columns form like this:

Name                                         Description                                   PowerState
----                                              -----------                                        ----------
WKV15300_06_07_2010_Active   Active snapshot                            PoweredOn
WKV15300_06_07_2010_InA...    InActive snapshot                          PoweredOff
WKV15300-Current                     Testing                                         PoweredOn

The culprit appears to be my Connect-VIServer SRG11503.fully.qualified.domain.name statement.  If I open powershell with the tookkit console and then simply run the commands on the command line I also get the expected rows and columns layout.  This is the output I prefer, why do I get different output when I try to launch a command after the Connect-VIServer command?

Any feedback would be appreciated.

PS.  I'm very new to powershell and this toolkit, I appologize if I used incorrect terms like command when I should have said cmdlet, I think.

0 Kudos
4 Replies
LucD
Leadership
Leadership

The way PowerCLI objects are displayed on screen is governed by the VMware.VimAutomation.Format.ps1xml file in the PowerCLI folder.

That file looks at the type of object and from the file is decided which output format to use.

If you use the PowerCLI prompt (your second run) that .ps1xml file is read and the default tabular output issed.

When you change your first script to say

...
get-vm $machine | get-snapshot | select name, description, powerstate | FT -AutoSize

you will always get tabular output.

PS: if you're still using the Infrastructure Toolkit I think you should also consider upgrading to PowerCLI 4.1

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
KroBaar
Contributor
Contributor

First, is the best way to post code on these forums by using the curly braces noformat markup, or what? Secondly, I tried adding the "| FT -AutoSize" statement that you suggested, but I get the following error:

out-lineoutput : Object of type "Microsoft.PowerShell.Commands.Internal.Format.

FormatStartData" is not legal or not in the correct sequence. This is likely ca

used by a user-specified "format-table" command which is conflicting with the d

efault formatting.

My guess is that you suggested that works with PowerCLI and I'm using the VMware Infrastructure Toolkit v1.5. If the PowerCLI is what I need, then I'll start playing around with that to see if I get the results I need.

0 Kudos
LucD
Leadership
Leadership

Easiest is to place your code betwwen meta-tags (without the blanks).

Yes, go for PowerCLI 4.1 and while you're upgarding check if you have PowerShell v2.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
KroBaar
Contributor
Contributor

Okay, fixed my post for others with proper tags.

I will upgrade to PowerCLI 4.1 and I'm currently only using powershell 1.0, so that could be a problem as well. Once I get that updated, I'll post back.

Thanks again for the prompt replies.

0 Kudos