Powershell Directory Listing

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Powershell Directory Listing

Post by jstevens »

I would like to generate a list of virtual environments using Powershell. The code below recurses into the package contents of each virtual machine file ie treats it like a directory folder. The end result should look like the example below: only four lines

Example: Contents of Z:\MyVirtualMachines
Z:\MyVirtualMachines\2021.01.31\Virtual01.vmwarevm
Z:\MyVirtualMachines\2021.02.01\Virtual02.vmwarevm
Z:\MyVirtualMachines\2021.02.28\Virtual02.vmwarevm
Z:\MyVirtualMachines\2021.03.31\Virtual03.vmwarevm

Code: Select all

Get-ChildItem -Path Z:\MyVirtualMachines -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object FullName
Regards,
John

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Powershell Directory Listing

Post by jstevens »

I was able to resolve this with:

Code: Select all

Get-ChildItem -Path "Z:\MyVirtualMachines" "*.vmwarevm" -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object -Unique FullName
Regards,
John