Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Remove Obsolete Folders

$
0
0

Good Afternoon

All users currently have access to their own folder on the network and have the base folder structure such as this

\\SERVERA\main\test.user\

\\SERVERA\main\john.smith\

\\SERVERA\main\test.user3\

However we need to remove a specific folder from each users directories where it has the word 'old' in there like so;

\\SERVERA\main\test.user\datafolder
\\SERVERA\main\test.user\datafolderold
\\SERVERA\main\test.user\datafolderold2

Therefore running the script will remove the 2 folders with OLD

I hope this explains the principle

Currently i have the following scripts but i am unable to get this to remove the folders as above

$location = '\\servera\main\'
foreach($loc in $location){
$users = Get-ChildItem "\\$location\" |select name
$users | where{ $_.Name -match [regex]'(old)'} 
write-host $users
}

Any help / advice greatly appreciated

Regards

Barrie


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>