VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

datatypes_powercli

Hi Luc ,

could suggest on the following scenerio.in which $snap1 and $snap which contains snapshot info of vms in cluster but defined differently as follows.

1:

$snap1= Get-VM -location $cluster  | Get-Snapshot |

    Select Name,@{N='VM';E={$_.VM.Name}},Created

and if we run $snap1|remove-snapshot  it throws error.

pastedImage_0.png

however if we define variable as follows

$snap=get-vm -location $cluster|get-snapshot

and then run $snap|remove-snapshot it works .

what is the difference in data being stored in $snap and $snap1 as both are of following types

pastedImage_1.png

Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There are two things happening here.

  1. There are more than 1 snapshots. Hence the array type that you see. That in itself is not a problem, because the Remove-Snapshot cmdlet accepts an array on the Snapshot parameter.
  2. When you use the Select-Object cmdlet the output is a special type of object, in this case a Selected.VMware.VimAutomation.ViCore.Impl.V1.VM.UniversalVirtualMachineImpl object. And that type is not accepted on the Snapshot parameter.

You can see the difference in type when you look at one element in the array, i.e.

$span1[0] | Get-Member


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

View solution in original post

5 Replies
LucD
Leadership
Leadership
Jump to solution

There are two things happening here.

  1. There are more than 1 snapshots. Hence the array type that you see. That in itself is not a problem, because the Remove-Snapshot cmdlet accepts an array on the Snapshot parameter.
  2. When you use the Select-Object cmdlet the output is a special type of object, in this case a Selected.VMware.VimAutomation.ViCore.Impl.V1.VM.UniversalVirtualMachineImpl object. And that type is not accepted on the Snapshot parameter.

You can see the difference in type when you look at one element in the array, i.e.

$span1[0] | Get-Member


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

jvm2016
Hot Shot
Hot Shot
Jump to solution

Thanks for yur response .

but i am getting same type for both.

pastedImage_0.png

pastedImage_1.png

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

pastedImage_0.png

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You are looking at the same variable twice, the 2nd one should be $snap[0]

Those types are different, as I explained


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

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

ok thnaks .

Reply
0 Kudos