Hi,
I'm trying to filter out results, to only show VMs that have been built in 2020. The line I am using below doesn't seem to work as it returns no results, however if I remove the where clause it shows plenty of VMs created in 2020. What am I doing wrong here?
Get-VM | Select-Object Name, @{N="created"; E={$_.ExtensionData.Config.createDate}} | where {$_.ExtensionData.Config.createDate -like "*2020*"}
Two issues, the Where-clause should come after the Get-VM.
And the property is of type DateTime, so it easier to compare with another DateTime object.
Select-Object Name, @{N="created"; E={$_.ExtensionData.Config.createDate}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Two issues, the Where-clause should come after the Get-VM.
And the property is of type DateTime, so it easier to compare with another DateTime object.
Select-Object Name, @{N="created"; E={$_.ExtensionData.Config.createDate}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks that worked! Is there a way to strip out the time and just show the date in the results?
Try like this
Select-Object Name, @{N="created"; E={$_.ExtensionData.Config.createDate.ToShortDateString()}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You saved the day once again. Thank you for your help!