Script which remove homefolder within a certain ou RRS feed

  • Question

  • I am kind of new to scripting and need some help creating a script for removing the homedir for all users in AD. As our AD structure contains ou for each site with users i have multiple ou to search

    I would further like the output to be displayed to a txt file where it could be nice to list the site name(ou) followed by their username and homedir and it have been removed or not

    So far i have created this

    #list users from a specific ou
    $users = Get-ADUser -Filter "*" -SearchBase "<ou-structure>" -Properties *

     $users | ForEach-Object {

     Write-Host "- " $_.Name
       if ($_.HomeDrive -ne $null) {
        Write-Host -NoNewline "|-  Current home:" $_.HomeDrive "->" $_.HomeDirectory": removing... "
        Set-AdUser -Identity $_.DistinguishedName -HomeDirectory $null -HomeDrive $null
        Write-Host "Done."

    Problems is that it is only searching the ou i specify and do not search any sub-ou

    I also would like the outcome to be copied to a txt file

    Thx for all help i can get

    • Moved by Bill_Stewart Monday, October 2, 2017 10:05 PM This is not "scripts on demand"
    Thursday, August 31, 2017 9:12 AM

All replies

  • Have a look at this thread


    Thursday, August 31, 2017 9:33 AM