A. I had a large folder of virtual machines I had exported. Each folder was a separate machine, and I wanted to run a script to import each VM in the folder. The first step was to use PowerShell to create the list of folders. To do that, I needed to list all child items in a path then check if the item is of type directory, as shown below.
PS E:\Virtuals> b<br><br><br><br><br>    Directory: E:\Virtuals<br><br><br><br><br>Mode                LastWriteTime     Length Name<br>----                -------------     ------ ----<br>d----         4/25/2011   6:27 AM            hypervserv<br>d----         4/24/2011   4:34 PM            PXETest<br>d----         4/25/2011   6:02 AM            savdalappv01<br>d----         4/24/2011   4:44 PM            savdalcb01<br>d----         4/24/2011   4:50 PM            savdalclient2.savilltech.net<br>d----         4/24/2011   4:56 PM            savdalclient3.savilltech.net<br>d----         4/24/2011   5:02 PM            savdalclient4.savilltech.net<br>d----         4/24/2011   5:08 PM            savdalcm01<br><br><br>The next step is to pass this output to another command. For example, below I just pass it to a command to list the fullname of the directory. You could use any function you need to.
PS E:\Virtuals> Get-ChildItem e:\virtuals | Where-Object { $_.Attributes -band  [System.IO.FileAttributes]::Directory } | ForEach-Object {Write-Host $_.FullName}<br><br><br>E:\virtuals\hypervserv<br>E:\virtuals\PXETest<br>E:\virtuals\savdalappv01<br>E:\virtuals\savdalcb01<br>E:\virtuals\savdalclient2.savilltech.net<br>E:\virtuals\savdalclient3.savilltech.net<br>E:\virtuals\savdalclient4.savilltech.net<br>E:\virtuals\savdalcm01<br>E:\virtuals\savdaldc11<br>E:\virtuals\savdaldpm01<br>E:\virtuals\savdalex10<br>E:\virtuals\savdalfs01