Hi,
I have a problem on this small report. Somewhere must be something wrong, because the output is not true if id do some tests!
The Report should only contains VMs´where snaphot is older than 24 hours or vm´s with snapshots older than 5 days(with exception tag).
The exclusion to hold snaphots until 5 days is a certian tag.
Based on this report the snapshots will be removed.
For quick testing the time value is changed to minutes!
$excludeVM = Get-Content 'C:\00\SnapshotReport\exclude.txt'
$includeVM = Get-Cluster test* | Get-VM | where{$excludeVM -notcontains $_.Name} | Sort-Object -Property Name
$includeVM
#
$tag = Get-Tag -Name 'snapshot5days' -Category 'snapshot'
clear-variable Snapreport
$Snapreport = $includeVM | Get-Snapshot | Where {(($_.Created -lt (Get-Date).addminutes(-1)) -and
($_.vm.Name | where{ (Get-TagAssignment -Entity $_).Tag.Id -notcontains $tag.Id})) -or ($_.Created -lt (Get-Date).addminutes(-5))}
$Snapreport
Correct, you need to add the Tag test as well.
$includeVM | Get-Snapshot |
Where {(((Get-TagAssignment -Entity $_.VM).Tag.Name -notcontains $tag.Name -and $_.Created -lt (Get-Date).AddDays(-1)) -or
((Get-TagAssignment -Entity $_.VM).Tag.Name -contains $tag.Name -and $_.Created -lt (Get-Date).AddDays(-5)))}
Update: corrected typo in snippet
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can you try with
Get-Snapshot -VM $includeVM |
Where {$_.Created -lt (Get-Date).AddDays(-1) -or
((Get-TagAssignment -Entity $_.VM).Tag.Id -contains $tag.Id -and $_.Created -lt (Get-Date).AddDays(-5))}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
in your proposal the secound filter after -or has no affect or?
Is there a way to use the tag name instead the id?
Correct, you need to add the Tag test as well.
$includeVM | Get-Snapshot |
Where {(((Get-TagAssignment -Entity $_.VM).Tag.Name -notcontains $tag.Name -and $_.Created -lt (Get-Date).AddDays(-1)) -or
((Get-TagAssignment -Entity $_.VM).Tag.Name -contains $tag.Name -and $_.Created -lt (Get-Date).AddDays(-5)))}
Update: corrected typo in snippet
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks Luc,
one id was to much..:-) ((Get-TagAssignment -Entity $_.VM).Tag.Id.Name
$includeVM | Get-Snapshot |
Where {(((Get-TagAssignment -Entity $_.VM).Tag.Name -notcontains $tag.Name -and $_.Created -lt (Get-Date).AddDays(-1)) -or
((Get-TagAssignment -Entity $_.VM).Tag.Name -contains $tag.Name -and $_.Created -lt (Get-Date).AddDays(-5)))}