I can get an individual VM's create date....
(Get-VM -Name testvm1).ExtensionData.Config.createDate
How do I get a list of VM's created in the past 10 days that are in my folder and subfolders in "vcenter1\test\dudesvms\"?
Thanks
Assuming that 'vcenter1' is also a folder, you could do something like this
$folderPath = 'vcenter1\test\dudesvms'
$folderPath.Split('\') |
$foder = Get-Folder -Name Datacenters
ForEach-Object -Process {
$folder = Get-Folder -Name $_ -Location $folder
}
Get-VM -Location $folder |
Select Name,@{N='CreationDate';E={$_.ExtensionData.Config.createDate}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I get a few of these errors then the list of VM's come up.....
Get-Folder : 6/15/2021 3:56:28 PM Get-Folder Get-Folder does not accept string input through pipeline. The string 'vcenter1' was ignored.
At line:6 char:26
+ $folderPath.Split('\') | Get-Folder -Name Datacenters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (vcenter1:String) [Get-Folder], ObnRecordProcessingFailedException
+ FullyQualifiedErrorId : Core_ObnArgumentTransformationAttribute_ProcessStringElement_InvalidPipelineArgument,VMware.VimAutomation.ViCor
e.Cmdlets.Commands.GetFolder
Possible difference in versions?
My version....
PowerCLI Version
----------------
VMware PowerCLI 11.0.0 build 10380590
---------------
Component Versions
---------------
VMware Cis Core PowerCLI Component PowerCLI Component 11.0 build 10335701
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.0 build 10336080
How do I order by date?
🐵
Answered my question.....
Sort-Object -Property CreationDate
I'm not sure what you are trying to do with $folderPath.Split('\') | Get-Folder -Name Datacenters
But that doesn't work.
You will have to show your complete code to allow me to investigate further
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So I removed "| Get-Folder -Name Datacenters" and the error is different but I only get it once then lists my VM's....
Get-Folder : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and
then try the command again.
At line:8 char:31
+ $foder = Get-Folder -Name $_ -Location $folder
+ ~~
+ CategoryInfo : InvalidData: (:) [Get-Folder], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetFolder
Full code...
Connect-VIServer "vc1.mystuff.net" #-AllLinked
$folderPath = 'vcenter1\test\dudesvms'
$folderPath.Split('\')
ForEach-Object -Process {
$foder = Get-Folder -Name $_ -Location $folder
}
Get-VM -Location $folder |
Select Name,@{N='CreationDate';E={$_.ExtensionData.Config.createDate}} | Sort-Object -Property CreationDate #-Descending
DisConnect-VIServer "vc1.mystuff.net" -Confirm:$False
You forgot the pipeline symbol (|) at the end of line 5.
And I had a typo in $folder.
Try with this version
Connect-VIServer "vc1.mystuff.net" #-AllLinked
$folderPath = 'vcenter1\test\dudesvms'
$folderPath.Split('\') |
ForEach-Object -Process {
$folder = Get-Folder -Name $_ -Location $folder
}
Get-VM -Location $folder |
Select Name,
@{N='CreationDate';E={$_.ExtensionData.Config.createDate}} |
Sort-Object -Property CreationDate #-Descending
DisConnect-VIServer "vc1.mystuff.net" -Confirm:$False
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference