2
votes

I am trying to write a PowerShell script that will search for all folders named "abc" within a network share. There a multiple instances of this folder located throughout this share all named "abc" in different DIR's

I would like to list the file and folder contents, of every folder named "abc" within said directory. So far I have got PowerShell to list all instances of folders named "abc" within the network drive, but I am stuck after that.

Can I pipe this into another command that will then search and list each folders contents?

1

1 Answers

4
votes

You can try something like htis

Get-ChildItem -Filter "abc" -Recurse -Path "\\myserver\share" | #Find abc
Where-Object { $_.PSIsContainer } | #Get only abc-folders
Get-ChildItem -Recurse | #Search through each abc-folder
Where-Object { !$_.PSIsContainer } #Get only files

The performance would be better if you run the script locally on the server or using psremoting(ex. using Invoke-Command). The problem is that it searches through all files and folders recursively before removing the files from the search result in that first Get-ChildItem line.

If you have PS 3.0 or PS 4.0, you can also use:

Get-ChildItem -Filter "abc" -Recurse -Path "\\myserver\share" -Directory | #Find abc-folders
Get-ChildItem -Recurse -File #Get files inside those folders