script to identify orphaned user home folders

Within our company we create user home folders with a PS script. Each user gets a home folder which gets the same name as the user's samaccountname.

Because sometimes a user's home folder is not removed at the same time like the account is disabled, we kind of lost track of inactive folders simply forgotten and folders which to keep. For that reason I'd like to run a script on a monthly basis which will check for each folder whether an user account with a corresponding sAMAccountname exists.

If a folder does not have a corresponding user name, then the name of that folder should be written into a csv file.

At the end of the script the csv file should be mailed to a mail recipient to be able to check what to do with these folders.

Being a complete PS noob and lacking persons around me with more PS knowledge I don't really know how to achieve this. Can somebody point me in the right direction?

September 4th, 2015 1:51pm

Hello CloudRookie,

just to point you in some directions:

To get your data:

  • Get-Item or Get-Childitem
  • Get-ADUser

To get your data per mail in csv format

  • Export-CSV
  • Send-Mailmessage

And the command which is most important

  • Get-Help NameofCommand

Regards,

Olaf

Free Windows Admin Tool Kit Click here and download it now
September 4th, 2015 2:03pm

See if this helps.

https://gallery.technet.microsoft.com/scriptcenter/Script-to-get-orphaned-ea7b3075

  • Edited by zxxzxx Friday, September 04, 2015 2:31 PM
September 4th, 2015 2:31pm

See if this helps.

https://gallery.technet.microsoft.com/scriptcenter/Script-to-get-orphaned-ea7b3075

Free Windows Admin Tool Kit Click here and download it now
September 4th, 2015 2:31pm

See if this helps.

https://gallery.technet.microsoft.com/scriptcenter/Script-to-get-orphaned-ea7b3075

September 4th, 2015 2:31pm

Thanks for your help guys!
Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 4:57am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics