Hi All,
Looking to create a powershell script that doesn't delete the home directory from everyone but deletes everything within there home directory and then remap their home directory to another location. Here is what I have so far but I am missing the second part because I'm not sure how to write that and in my current code I believe it would delete the homedirectory comopletely.
Import-Module ActiveDirectory
$searchOU = "OU=Disabled_Users,OU=Users,OU=whatever,DC=domain,DC=com"
Get-ADuser -filter * -searchbase $searchOU -properties DistinguishedName | Select -expandProperty DistinguishedName |
ForEach {
$user = [adsi]"LDAP://$_";
If (Test-Path $user.homedirectory)
{ Remove-Item $user.homedirectory -recurse -force
} ;
}