output a list of file directories on a file server that will show users (Home Drives)

asked 2022-06-14T10:54:40.543+00:00
Mark Stogdale 6 Reputation points

i would like to use powershell to output a list of file directories on a file server that will show users (Home Drives) what would be the best method for this basically i want to output all the Folder Directories on a file server to cross reference against AD to chedk before a migration

Windows Server Migration
Windows Server Migration
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Migration: A Microsoft solution area focused on providing organizations with a cloud solution that supports their real-world needs and meets evolving regulatory requirements.
306 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
4,618 questions
No comments
{count} votes

2 answers

Sort by: Most helpful
  1. answered 2022-06-14T11:32:06.18+00:00
    Newbie Jones 1,171 Reputation points

    The following function will get a list of folders that have specific permissions set if that is what you need. (Warning, it can take a long time to run)

    function Get-AclAccess {  
    param ($folder='.', $outfile='aces.csv')  
      
       dir $folder -recurse | Where{$_.PSIsContainer} |  
       ForEach {get-acl $_.pspath}| ForEach {  
           $Path=$_.pspath  
           $_.access | Where {$_.IsInherited -eq $False} |  
           Add-Member -MemberType noteproperty -name path -value $path -passthru  
       } | Export-Csv $outfile -Notype  
    }   
    
    No comments

  2. answered 2022-06-14T13:12:58.863+00:00
    Newbie Jones 1,171 Reputation points

    Or if you just want the folders. (Although this will also report on all subfolders in users home drives).
    You may want to remove the -recurse attribute if all of the home drives are at the same level.

    function Get-Folder {  
    param ($folder='.', $outfile='folders.csv')  
      
       $results=@()   
      
       dir $folder -recurse | Where {$_.PSIsContainer} |  
       ForEach {  
            $props=@{Path=$_.FullName}  
            $results +=  New-Object -TypeName PSObject -property $props  
          
       }   
         
       $results | Export-Csv $outfile -NoTypeInformation  
      
    }