$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
I'm not sure what you are trying to say, but Get-VM | $Mylist[0] will not work either
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Because the Name parameter on the Get-VM cmdlet is not defined as a parameter that can be provided through the pipeline.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
you are using this in back order . 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 :
I'm not sure what you are trying to say, but Get-VM | $Mylist[0] will not work either
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
My bad , 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 ?