VMware Cloud Community
Pegasjus
Contributor
Contributor
Jump to solution

Get-VM and Get-Snapshot does not return Host/VMHost

Hi,

been banging my head a bit lately on this one.

When I run Get-VM | select VMHost, Name I get a return on the VMhost and the guest.

If I add a tad to the selection such as Get-Snapshot and a few more selections I do not get the VmHost but all the rest of the information comes along just fine.

Get-VM | Get-Snapshot | select VMHost, Name, Description, SizeMB

Can anybody be so kind as to point out what I am doing wong.

Finally this is part of something I plan to run a bit more thoroughly so the whole line is something like this:

Get-VM | Get-Snapshot | select VMHost, Name, Description, SizeMB, @{N="DaysOld"; E={((Get-Date) - $_.Created).Days}} | ? {$_.DaysOld -gt 7} | Export-Csv "C:\Filename.csv"

The commandlet works but just not with the host, which quitely franky would be useful to have Smiley Happy

//Martin

Message was edited by: maishsk Subject was changed

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

oi Martin,

you are selecting properties from a snapshot object and not from a virtual machine object. A snapshot object has different properties. You can use the following code:

Get-VM |
Get-Snapshot |
Select-Object -Property @{N="VMHost";E={$_.VM.VMHost.Name}},
@{N="VM";E={$_.VM.Name}}, Name, Description, SizeMB,
@{N="DaysOld"; E={((Get-Date) - $_.Created).Days}} |
Where-Object {$_.DaysOld -gt 7} |
Export-Csv "C:\Filename.csv" -NoTypeInformation -UseCulture 

Message was edited by: maishsk Subject was corrected

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

oi Martin,

you are selecting properties from a snapshot object and not from a virtual machine object. A snapshot object has different properties. You can use the following code:

Get-VM |
Get-Snapshot |
Select-Object -Property @{N="VMHost";E={$_.VM.VMHost.Name}},
@{N="VM";E={$_.VM.Name}}, Name, Description, SizeMB,
@{N="DaysOld"; E={((Get-Date) - $_.Created).Days}} |
Where-Object {$_.DaysOld -gt 7} |
Export-Csv "C:\Filename.csv" -NoTypeInformation -UseCulture 

Message was edited by: maishsk Subject was corrected

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
Pegasjus
Contributor
Contributor
Jump to solution

Hi Robert,

thanks worked a charm! Smiley Happy I was kinda hoping that was what the problem was, still new with this though.

//Martin

Message was edited by: maishsk Subject was corrected

0 Kudos