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)
7,884 times
Add to favorites
Active Directory
9/23/2015
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Return folder attributes!!
    1 Posts | Last post February 14, 2019
    • Hi all 
      
      Does anyone know how to add a feature where it would return date modified, date accessed, date created and the owner? Your script is awosome. Thank you so much 
      I really appreciate your help.
  • Check specific domain
    1 Posts | Last post January 23, 2019
    • I do have multiple domains. How can I specify the domain to be checked?
      Let's say the DN of the domain to be checked should be : DC=scrooge,DC=be
      
      And that the computer/server where the script is located is in DC=altair,DC=be
      
      Their is a trust between the domains and my account has access to all of them.
  • Roaming Profiles
    2 Posts | Last post October 13, 2018
    • Is there a way to drop the ".V4", or ".V5", etc from Roaming profile folders? (i.e. "samaccountname.V6")
    • Never mind, used the first comment from Andrei Vlad and it worked!
  • Error checking
    1 Posts | Last post April 04, 2017
    • Hi,
      Is there any chance of adding error checking? If this script is run under the server's local admin account it will class all folders as orphaned and move them all to the archive. I'm currently moving 400GB of data back to where it came from...
      
      Silly mistake on my part, but I'm guessing the script will do the same if this is run as a scheduled task and the password for the account expires, or is changed.
      
      Thanks.
  • fileserver in resource domain, accounts in two account domains
    1 Posts | Last post March 06, 2017
    • Jaap,
      
      Is it possible to have two searchbases?
      We have one domain for staff users, and one domain for students. The file server is in a third resource domain (to make things simple...) All domains trust each other.
  • Update with user lastlogontime
    2 Posts | Last post February 17, 2017
    • Hey, just an update, i added support for "Days" Parameter to check if user hasn't logged in in X days, just above the case for DisplayAll and this new parameter,
      
      "
      param(
          [Parameter(Mandatory=$true)]
          $HomeFolderPath,
          $MoveFolderPath,
          $SearchBase,
          [string[]]$ExcludePath,
          [switch]$FolderSize,
          [switch]$MoveDisabled,
          [switch]$DisplayAll,
          [switch]$UseRobocopy,
          [switch]$RegExExclude,
          [switch]$CheckHomeDirectory,
          #A.E.
          [INT]$Days
      )
      "
      
      "
          #A.E.
          # Users that have not logged in for X number of days
          } elseif ([DateTime]::FromFileTime([STRING]$ADResult.Properties.lastlogontimestamp).Date -le (Get-Date).AddDays($Days).Date) {
              $HashProps = @{
                  'Error' = 'Account Has Not Logged in {0} Days' -f $Days
                  'FullPath' = $_.FullName
              }
      
              if ($Days) {
                  $HashProps.LastLogonTimeStamp = [DateTime]::FromFileTime([STRING]$ADResult.Properties.lastlogontimestamp)
              }
      
              if ($FolderSize) {
                  $HashProps.SizeinBytes = [long](Get-ChildItem -LiteralPath $_.Fullname -Recurse -Force -ErrorAction SilentlyContinue |
                      Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue | Select-Object -Exp Sum)
                  $HashProps.SizeinMegaBytes = "{0:n2}" -f ($HashProps.SizeinBytes/1MB)
              }
      
              if ($MoveFolderPath -and $MoveDisabled) {
                  $HashProps.DestinationFullPath = Join-Path -Path $MoveFolderPath -ChildPath (Split-Path -Path $_.FullName -Leaf)
                  Move-Item -LiteralPath $HashProps.FullPath -Destination $HashProps.DestinationFullPath -Force
              }
      
              # Output the object
              New-Object -TypeName PSCustomObject -Property $HashProps
      
          # Folders that do have active user accounts are displayed if -DisplayAll switch is set
          }
      "
      
      thanks
    • Hi Avi, 
      
      Ive tried adding this into the script...im currently just trying to list orphaned/disabled folders not accessed in say 365 days but i wont be moving/deleting in the first instance...just listing in the output. 
      However when i run this the output just shows something like;
      #TYPE System.String
      Length
      4
      
      I was running the cmd - .\Get-OrphanHomeFolder.ps1 -HomeFolderPath \\server\userfolder$ -FolderSize -Days 365 | Export-Csv C:\Temp\Users1Days365.csv
      
      Would you be able to advise on how im going wrong?
      
      Thanks
      Donna
      
      
  • Home Folder - Last Access Date
    1 Posts | Last post February 16, 2017
    • Hi all 
      
      Does anyone know if theres a way to add something to the script so that it outputs the last accessed/modified dates next to each home folder?
      Our company are a bit hesitant in removing all the orphaned folders without knowing and we would like to try to aim to remove orphaned folders not accessed in say 1 year. 
      
      Thanks!
      Donna
  • Search email alias as well
    1 Posts | Last post January 17, 2017
    • I deal with name changes from marriages and divorces often.  My AD keeps track of names using the mailNickname attribute.  Is it possible to compare this value after the sAMAccountName if the folder name doesn't match the sAMAccountName?  And, if the mailNickname value matches the homeDirectory name, leave the homeDirectory as is?
  • departments
    1 Posts | Last post October 12, 2016
    • Hello. Thank you for your script. If it is not too much trouble it would be nice to also have their department show up in the output as another switch. Sometimes we need to know what departments are eating up all of our drive space and this would help separate their users quite simply.
  • Accounting Renames
    3 Posts | Last post September 27, 2016
    • Is there a way to modify the script so it takes in to account renames?
      
      We typically rename accounts but sometimes forget to change the homefolder name as well. I guess I don't really know how to solve that without looking at the profilepath name instead of samAccountName, but that probably introduces other issues or at the very least extra overhead during the process.
      
      By the way, thanks for the script! It did work as expected.
    • Wow, I completely missed the -CheckHomeDirectory switch at the end of the documentation. Please ignore :D
    • No problem, the script comes with a number with parameters. Glad to hear you found the solution before I could answer this for you!
      
      
      Regards,
      
      Jaap Brasser
1 - 10 of 37 Items