Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Looking to create a PowerShell script that deletes everything under all users home directory and remaps home directory to new location

$
0
0

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 

} ;

}


Viewing all articles
Browse latest Browse all 6937

Trending Articles