Use PowerShell to get user home directory, Home Drive, Last Logon and account status
Valentin Komarovskiy, MBA
Solving complex business problems and alleviating technical pain points to improve efficiency and reduce risks.
You can user PowerShell to get the user Home Drive, Home Directory, last logon date and account status. This can help with user account cleanup and home drive / home folder cleanup. This script needs to be run with Active Directory PowerShell module. For more info on how to add and execute the module please see https://learn.microsoft.com/en-us/powershell/module/activedirectory/?view=windowsserver2022-ps
Get-ADUser -Filter 'PasswordNotRequired -eq $false' -Properties ProfilePath, HomeDirectory, HomeDrive, LastLogonDate, UserPrincipalName, Enabled | Select Name, LastLogonDate, SamAccountName, ProfilePath, HomeDirectory, HomeDrive, UserPrincipalName, Enabled | Export-Csv -path "c:\temp\userlistProf_logondate3.csv"
After export runs, open the file with Excel and save as XLSX
Now you can add a filter and use it to view the information you need, for example home drives of enabled account only, or account that have not been logged on to for a certain period of time.