M
M
myxz2019-05-31 19:50:04
PowerShell
myxz, 2019-05-31 19:50:04

How to delete folders using account list from csv file?

Connoisseurs, good evening, tell me, I have a list (logins) of inactive accounts downloaded from AD in a .CSV file.
I need to delete user folders buried on different network resources, folders are named the same as user logins. There are 120 accounts in the list, while the remaining active accounts not from the file should remain
. Example:
npetrov - login from csv. The path to the network resource \\domain\public\personal-folders\npetrov Tell me
who has come across something similar or has already implemented something similar. I will be immensely grateful.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2019-06-01
@myxz

To solve such problems, I recommend using Powershell
. You can use the script below by replacing the paths in the $csv and $FolderPath variables with your own
. Before using the script, I recommend that you first practice on some test folders to make sure that everything works exactly as you need.
$csv = "C:\temp\logins.csv"
$FolderPath = "\\domain\public\private-folders"
$logins = Import-Csv -Path $csv | Select-Object -ExpandProperty name
Foreach ($login in $logins)
{Remove-Item -path "$FolderPath\$login" -Force}

E
Eugene, 2019-06-01
@Evgenym

Solved the same problem. How did. I took Powershell, went around the folders, getting information about the full path and owner, because the user could change the name, the name is written differently than in AD. Saved data in CSV as "Full path; Owner account". Then I read this CSV and went through it in a loop, checking each account for a blocking condition, existence, etc. Further, if there was no account, it was locked for longer than a certain period, transferred the folder to a separate disk and made a record in the log file. After that, he took the transferred folders, transferred them to a regular screw and put them in a locker.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question