by stanger at 2013-01-11 05:23:49
Hi All,by Klaas at 2013-01-11 07:40:35
I am new here and quite new to powershell. Thing is that I have ~50 servers with their shares for users, shares names are exact usernames+$ f.e. ABCD user has share \abcdserver1\ABCD$
My issue is that now I have to find and delete all unneeded shares for un-existing users.
What I have:
list of all servers and each server share name
What I need:
1. script or PS command to find out all unexisting users shares on separate server from user-list in txt file;
2. script to delete all folders for unexisting users from remote servers.
I would appreciate any help.
Depending on the structure of the shares.txt files you can decide to use Get-Content and some string manipulation to compose an array of strings or Import-Csv to collect shares as objects.
The same goes for the users.txt.
Loop through the share collection and check for each one if it exists in the user collection. If not, delete the folder with Remove-Item.
Or you could collect the shares ‘live’ from your servers instead of using a .txt.
It might help if you post a sample of your files and the code you have managed to write so far.