Hello,
I have a Custom Attribute for Dates(DD/MM/YYYY) in vCenter and I am attempting to gather VM's prior to that date however my statement does not take seem to take year into account. So if I set a date in the future e.g. 1/15/2012 the script lists them as prior to current date which is incorrect and any dates beyond the current date but still in 2011 are not shown which is correct. Any ideas would be greatly appreciated.
$currentdate = Get-Date
$currentdate = $currentdate.ToShortDateString()
Get-VM | Get-Annotation -CustomAttribute "Expires" | ?{$_.Value -le "$currentdate"}
Verions:
vCenter - 4.1.0.12319
PowerCLI - 4.1.1.2816
Cheers!
Have you considered converting the date you get from the attribute. Try this
$currentdate = Get-Date
Get-VM | Get-Annotation -CustomAttribute "Expires" | ?{(Get-Date $_.Value) -le $currentdate}
Have you considered converting the date you get from the attribute. Try this
$currentdate = Get-Date
Get-VM | Get-Annotation -CustomAttribute "Expires" | ?{(Get-Date $_.Value) -le $currentdate}
That worked like champ, thank you so much!
No problem. Glad I could help.
The trick is keeping them both in System.DateTime format for the compare.