VMware Cloud Community
jravnsba1
Contributor
Contributor
Jump to solution

Passing items from array to Get-VM ?

$MyList = @()

$MyList += "VM1";

$MyList += "VM2";

$Mylist[1]|Get-VM;

This gives an error instead of showing the result for Get-VM VM2

Get-VM : Cannot process argument transformation on parameter 'Location'. Strings as pipeline input are not supported.

At line:4 char:12

+ $Mylist[1]|Get-VM;

+ ~~~~~~

+ CategoryInfo          : InvalidData: (VM2:String) [Get-VM], ParameterBindingArgumentTransformationException

+ FullyQualifiedErrorId : ParameterArgumentTransformationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

This workaround works:

$Mylist[1] | ForEach-Object{ Get-VM $_}

Why isn't is possible just to use  $Mylist[1] | Get-VM

Joern Ravnsbaek
Tags (2)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I'm not sure what you are trying to say, but Get-VM | $Mylist[0] will not work either Smiley Sad


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

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

Because the Name parameter on the Get-VM cmdlet is not defined as a parameter that can be provided through the pipeline.

pipeline.png


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

0 Kudos
vijayrana968
Virtuoso
Virtuoso
Jump to solution

you are using this in back orderSmiley Happy . Values are already stored in $Mylist, you have to call these values by [0], [1], [2]... so on. This will work in this way :

Use Get-VM command before.

Get-VM | $Mylist[0]

Get-VM | $Mylist[1] 

Example :

pastedImage_1.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm not sure what you are trying to say, but Get-VM | $Mylist[0] will not work either Smiley Sad


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

vijayrana968
Virtuoso
Virtuoso
Jump to solution

My bad Smiley Sad, To be honest, I don't know the fundamentals but I was tweaking small scripts and one liner in DPM shell back in year or two for my day to day work where I was managing Tape library though shell. I have a little bit idea about variable, pipeline and loop.

I guess then Get-View can be used and then select-object with this.

$Mylist[0] | Get-View | select-object .......

Or it can't be ?

0 Kudos