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?