Script to get orphaned home folders and folder size

This script queries AD with the name of the home folder. If this query does not result in an account or a disabled account the script will list the folder size with the folder path and error message.

 
 
 
 
 
4.3 Star
(12)
9,408 times
Add to favorites
Active Directory
9/23/2015
E-mail Twitter del.icio.us Digg Facebook
  • Cannot move orphaned home folders from DFS
    2 Posts | Last post May 24, 2013
    • .\Get-OrphanHomeFolder.ps1 -HomeFolderPath \\DFS\priv$\user -MoveFolderPath \\server01\e$\old\user
      
      Move-Item : Source and destination path must have identical roots. Move will not work across volumes.
      At C:\Users\Administrator\Desktop\Get-OrphanHomeFolder.ps1:41 char:22
      +             Move-Item <<<<  -Path $HashProps.FullPath -Destination $HashProps.DestinationFullPath -Force
          + CategoryInfo          : WriteError: (\\damwatch.local\private$\user\andrews:DirectoryInfo) [Move-Item], IOExcept
         ion
          + FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand
      
    • Hello DirtyApe,
      
      This is indeed a limitation of Move-Item. A workaround for the time being is to first move it to a folder on the same volume and then use robocopy to copy it to the alternate location.
      
      If that is not an option for you I can also implement it in the script, add the -Robocopy switch to utilize robocopy instead of move-item. Let me know if that answers your question.
  • Multiple Home folders and off behavior?
    5 Posts | Last post May 24, 2013
    • Is there a way to execute the script with multiple home folders? Also,
      I've noticed the script seems to fail on home directories containing spaces, hyphens, underscores, and apostrophes.
      
      Example:
      \\server01\distanceusers\Christy.Baxter-Robins
      \\server01\a1users\Thomas_Smith
      \\pack08\Homeusers\Jennifer.L'Amoreaux
      \\pack08\Homeusers\Ted Brown
      
    • I have updated the script to use the LiteralPath parameter instead of the Path parameter where applicable. This should resolve the issue. If you download version 1.5 you should no longer run into this issue.
    • Version 1.5 is giving the following:
      cmdlet Split-Path at command pipeline position 1
      Supply values for the following parameters:
      Path[0]:
      
      Also is there a way to use multiple home folders?
    • Line 71 reads:
          $CurrentPath = Split-Path -LiteralPath $_ -Leaf
      should it read:
          $CurrentPath = Split-Path $_ -Leaf
    • That is correct, I inadvertently broke the scripts functionality by supplying the -LiteralPath parameter for Split-Path instead of -Path. I have fixed this in the script where it was applicable. This has been resolved in version 1.5.1
  • Script for disabled accounts
    3 Posts | Last post March 08, 2013
    • Hi Jaap
      Your script works great for moving folders. Thanks!
      
      Maybe the script is written only for moving the homefolders for the non-existent AD accounts and since it does not move folders for the disabled accounts.
      Would it be possible for you to create another script or modify this one, so that I can move the folders for disabled accounts as well.
    • Jaap, well I figured out editing the script to move the homefolders for disabled accounts as well. But I constantly keep getting the below error when running the script:
      
      Cannot index into a null array.
      At X:\Path to the Orphan Script\Get-OrphanHomeFolder2.ps1:91 char:66
      +     } elseif (([boolean]($ADResult.Properties.useraccountcontrol[ <<<< 0] -band 2))) {
          + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
          + FullyQualifiedErrorId : NullArray
      
      
      Could you please tell me why or how to fix this error?
    • You are getting this error when there are no results in $ADResult. You could work around this by first checking if there are any results. I don't know what changes you made to the script, so I just upload a 1.4 version of the script that does support moving the Disabled user folders. Can you confirm if you get the same errors if you run the updated version of the script?
  • Editing Scripts
    1 Posts | Last post February 13, 2013
    • Hi Jaap, apologies, I know nothing about scripting but I really want to start using them as I feel I could get so much more done in so much less time! This script seems ideal for me but I dont know how to edit it for my site. 
      
      My file server is called file1 and the home folder share is \\file1\home$
      My move folder is \\file1\orphan
      
      I tried editing where it says home and move folder but I'm assuming now thats not what I need to do. I run power shell and get errors such as 
      param( 
          [Parameter(Mandatory=$true)] 
          $\\file1\home$, 
          $\\file1\Orphan, 
          [switch]$FolderSize 
      ) 
      # Check if HomeFolderPath is found, exit with warning message if path is incorrect 
      if (!(Test-Path -Path $\\file1\home$)){ 
          Write-Warning "HomeFolderPath not found: $\\file1\home$" 
          exit 
      } 
       
      # Check if MoveFolderPath is found, exit with warning message if path is incorrect 
      if ($file1\Orphan) { 
          if (!(Test-Path -Path $file1\Orphan)){ 
              Write-Warning "MoveFolderPath not found: $file1\Orphan" 
              exit 
          } 
      } 
       
      Nothing happens as far as moving folders. Could you help me?
      
      Best
      Ciaran
  • Compliment
    2 Posts | Last post January 16, 2013
    • Not a question, just a compliment on a great script. I was just going to write this myself. Well written and extremely useful!
    • Hi,
      
      How to add samaccountname, lastlogon and lastlogon > 90 days please ?
  • samaccountname & lastlogon
    1 Posts | Last post January 14, 2013
    • Hi,
      
      Could you update your script to add samaccountname and last logon and last logon more 90 days please :)
      
      Thanks
  • Archiving
    3 Posts | Last post December 12, 2012
    • Hi,
      
      Sorry for the newbie question, can you add to this script so if the folder is orphaned then it is moved to a archived users folder?
      
      Thanks
      
    • Hello Saylum, yes this is a possibility. I will update the script to include a parameter for this.
    • Hello,
      
      I have uploaded a new version of the script that includes the -MoveFolderPath parameter. This parameter will move any found Orphan Home Folders to the path specified in that parameter.
      
      Does that satisfy your request?
31 - 37 of 37 Items