Check user home directory settings against folder names

Posted: June 29, 2015 in Active Directory, File Operations, Scripts

Nothing too exciting in this one, just had to do a quick comparison of user home folders against what was set in Active Directory as part of file server permission’s remediation task.

Import-Module ActiveDirectory -ErrorAction Stop

$HomeDriveSharePath = "\\dfsroot\public$\home"

$HomeDirectories = Get-ChildItem $HomeDriveSharePath

ForEach ($HomeDirectory in $HomeDirectories){

# Set reference variables
$HomeDirectoryPath = $HomeDirectory.FullName
$HomeDirectoryName = $HomeDirectory.Name

# Attempt to get AD user details based on the directory name matching the login name.
# Include the HomeDirectory attribute for comparison
$ADUser = Get-ADUser -Properties HomeDirectory -Filter { SamAccountName -eq $HomeDirectoryName }

# No do the comparison, see if we have directories with no matching AD user or user's who's home directory path doesn't match up.
If ( $ADUser.HomeDirectory -ne $HomeDirectoryPath ){

If ( $ADUser.Name -ne $null){
$ADUserName = $ADUser.sAMAccountName
$ADUserName = "Unknown"
Write-Host "Could not match home directory setting for $ADUserName with home directory of $HomeDirectoryPath"



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s