VMware Cloud Community
mazdajai
Contributor
Contributor
Jump to solution

Exclude results in get-snapshot

Is there a way to exclude a VMhost with get-snapshot? I need to exclude VMs with GuestOS (Windows 7 \ XP) that sits on one VMHost.

I can use get-vm + Name or Guest OS filter but it will slow the entire query down.

connect-viserver XXXXX

$vm = get-vm

$snapshots = Get-Snapshot -VM $vm

foreach ( $snap in $snapshots )

    {

    if ( $snap.Created -lt (Get-Date).AddDays( -$Age ) )

        {

    $Snap | Select-Object -Property *

    @{N="HostName";E={$_.vm}},

    @{N="SizeGB";E={[math]::Round($_.SizeGB)}},

    @{N="CreatedOn";E={$($_.Created -replace $time)}}

    $count++   

        }

    }

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try replacing this line

$vm = get-vm

with

$esxName = "ToBeExcluded"

$vm = get-vm | Where {$_.VMHost.Name -ne $esxName}


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

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Try replacing this line

$vm = get-vm

with

$esxName = "ToBeExcluded"

$vm = get-vm | Where {$_.VMHost.Name -ne $esxName}


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

Reply
0 Kudos
mazdajai
Contributor
Contributor
Jump to solution

Thanks. I modified my script and is doing a test run(takes a while). I am measuring the performance, will report back in few hours.

$esxName1 = "csms1.example.com"

$esxName2 = "*esx*v.example.com"

$vm = get-vm | Where {$_.VMHost.Name -ne $esxName1 -and $_.VMHost.Name -notlike $esxName2}

Reply
0 Kudos
mazdajai
Contributor
Contributor
Jump to solution

Thank you!!

Reply
0 Kudos