I need to identify all folders that match \Foldername1\Foldername2 under \Users…
\users has multiple %USERNAME% directories under it.
Then delete all files under Foldername2
I need to identify all folders that match \Foldername1\Foldername2 under \Users…
\users has multiple %USERNAME% directories under it.
Then delete all files under Foldername2
Ok you could use Get-ChildItem to find the directory and Remove-Item to delete it’s contents.
THanks, but if I understand correctly Get-ChildItem only spans the current directory. I have to find “Folder3” under
C:\Users\user1\folder1\folder2\folder3
C:\Users\user2\folder1\folder2\folder3
C:\Users\user3\folder1\folder2\folder3
C:\Users\user4\folder1\folder2\folder3
Where each username is unique, and then delete the contents of all files in Folder3 for each user. I am also new to PS, so looking for examples …
Thanks.
Something like this:
Get-ChildItem -Path C:\Users\ -Include folder1 -Recurse -Depth 2 -Directory | Get-ChildItem -Directory -Include folder2 | Get-ChildItem -Directory -Include folder3
Test the output and adjust accordingly; finally pipe the output to Remove-Item.
There are a few examples on the MS docs page.
You can use wildcards in the path.
Get-ChildItem -path c:\users\*\folder1\folder2\folder3
Similarly you could use Resolve-Path.
Resolve-Path -Path c:\users\*\folder1\folder2\folder3