Export users with home directory set to share

This PowerShell script simplifies Active Directory user management. It quickly identifies users with network share home directory paths within a specified OU. You can easily view their details, such as names, account names, and paths, and export this information to timestamped CSV files. It's a practical tool for maintaining an organized AD environment.

# Get all AD users within the specified OU
$users = Get-ADUser -Filter * -Properties HomeDirectory

# Define an empty array to store users without a local path for the Home folder
$ADUsersWithPath = @()

# Loop through each user and check if the HomeDirectory property is not a local path
foreach ($user in $users) {
    if ($user.HomeDirectory -like "\\*") {
        $ADUsersWithPath += $user
    }
}

# Display the list of users without a local path for the Home folder
$ADUsersWithPath | Select-Object Name, SamAccountName, HomeDirectory
$ADUsersWithPath | Export-CSV ".\$(Get-Date -Format yyMMdd) AdUsersWithHomeDirectoryPath.csv"

 


Revision #1
Created 19 September 2023 12:27:27 by Luca Noah Caprez
Updated 19 September 2023 12:33:30 by Luca Noah Caprez