Get-Share Permissions

This little script will enumerate all the shares on a computer, and list the share-level permissions for each share.  It uses WMI to retrieve the shares, and to list the permissions.  Thanks to Michal Gadja for his input (via the Library).

3.8 Star
35,739 times
Add to favorites
E-mail Twitter Digg Facebook
  • Addional Line
    1 Posts | Last post June 06, 2019
    • In order to get not only the share name but the path to it as well I added an addional line. After $acl = $null on line 43 I inserted a new line and added:
      Write-Host (Get-WMIObject -Class Win32_share -Filter "name='$Share'"  -ComputerName $computer | Select -ExpandProperty Path) -ForegroundColor Green
      There is probably a cleaner way than rerunning a search but would ahve nmeant changing more of the code and not just inserting a line.
  • output result
    1 Posts | Last post August 20, 2018
    • Hi,
      I tried to launch the script and get the result on a file but have an issue.
      I wanted to add the Share name in the result, so I did something as so:
      foreach($ace in $SD.DACL){
                  $UserName = $ace.Trustee.Name      
                  If ($ace.Trustee.Domain -ne $Null) {$UserName = "$($ace.Trustee.Domain)\$UserName"}    
                  If ($ace.Trustee.Name -eq $Null) {$UserName = $ace.Trustee.SIDString }      
                  [Array]$ACL += New-Object Security.AccessControl.FileSystemAccessRule($UserName, $ace.AccessMask, $ace.AceType)
                  } #end foreach ACE            
              } # end try  
              { Write-Host "Unable to obtain permissions for $share" }  
      I added $objShareSec under foreach($ace in $SD.DACL){ 
      And I kinda got the result I was expecting but, when I try to export it in a file, I only get $ObjShareSec result in my file.
      How can I be able to have all the results plz?
  • Newer versions of Windows have built in cmdlet for this
    3 Posts | Last post December 18, 2017
    • Hi!
      Just wanted to remind everyone that the latest versions of Windows (Windows 8, Windows 8.1, Windows Server 2012 and Windows Server 2012 R2) have a built-in cmdlet for this:
      Get-SmbShareAccess -Name xxx
      You can also do:
      Get-SmbShare | Get-SmbShareAccess
      Jose Barreto
    • This was an incredible time saver!  Thank you.  Added the sort-object $share to alphabetize this too.  Thanks again
    • Get-SbmShare will only show local shares. I have never been able to get it to connect to a remote system.
      The examples and details make it look like this cmdlet should be checking network neighborhood automatically and populating a list of shares your system can see, but that does not happen. I see only shares on my system, no matter what level of credentials I use. Using -Name just results in an "No MSFT_SMBShare objects found" message.
      I'd much rather use these built-in cmdlets because I can further refine the output to display only the few bits of information I an interested in instead of dumping it all to text and then searching it manually.
  • about the .txt files
    3 Posts | Last post December 18, 2017
    • I'm very new to powershell in general and I'm confused about how one would right server names in the .txt file.
      I'm trying to list multiple server names and I'm not too sure what is the proper way to separate the names.
      a b c 
    • After a few days of looking up, the problem isn't that im writing the files wrong but the program will automatically overwrite which name it will find a share for depending on what ever the last name is. Ex a then b it will choose only b but if its b then a it will choose a
    • To read the contents of a text file with one server name per line (\r\n delimeter) and run each one through Get-SharePermisions individually.
      $serverList = Get-Content serverlist.txt
      foreach ( $line in $serverList ) { .\Get-SharePermissions.ps1 -$line }
      This is how I got it working for me.
  • evryone full control
    1 Posts | Last post August 17, 2017
    • can i use it for display only the share with evryone full control?how i can modify it?
  • Unable to obtain permissions error
    2 Posts | Last post November 10, 2016
    • Getting the following error: (I am a newbie to PowerShell as well)
      Get-WmiObject : Invalid query
      At C:\Get-SharePermissions.ps1:46 char:33
      +     $objShareSec = Get-WMIObject <<<<  -Class Win32_LogicalS
      e $computer
          + CategoryInfo          : InvalidOperation: (:) [Get-WmiOb
          + FullyQualifiedErrorId : GetWMIManagementException,Micros
      Unable to obtain permissions for \\servername\sharename
    • Here is the whole error:
      Get-WmiObject : Invalid query
      At C:\Get-SharePermissions.ps1:46 char:33
      +     $objShareSec = Get-WMIObject <<<<  -Class Win32_LogicalShareSecuritySetting -Filter "name='$Share'"  -ComputerName $computer
          + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
          + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
      Unable to obtain permissions for \\ServerName\ShareName
  • Not able to run Script
    2 Posts | Last post September 13, 2016
    • Thanks for posting the script Bigteddy.  I am not able to run the script and I am getting "The term '.\Get-SharePermissions' is not recognized as the name of a cmdlet, function, script file, or operable program."  I have set the ExecutionPolicy to UnRestricted and attempted to sign the script to no avail, I am unable to run.  What else is needed to enable the script to run?  (I'm a newbie as well.)
    • resolved as permissions issue. 
  • Script for Share permission
    1 Posts | Last post December 29, 2015
    • Hi,
      I have Windows File Server and config. is Windows File Server 2012R2 and its VM configured on Hyper-V now I want list of all share folder name with share permission details (means user have which permission of folders).  I need this detail in .CSV.  Could you please give me the script which provide all the details?
      Kaushal Shah
  • Write Server Name to output file
    4 Posts | Last post November 06, 2015
    • Is there a way of writing the Server name to the output file for each server that is checked?
    • Yes, change the Write-Host line for the share from:
      Write-Host $share -ForegroundColor Green
      to just
      Save and run again.
    • I removed the -ForegroundColor Green and the output still does not have the server names.
    • The lines should look like this.
      foreach ($share in $shares) {  
          $acl = $null  
           $('-' * $share.Length) 
      If you want the path and formatting to show up in the output file.
  • Export to file
    1 Posts | Last post March 18, 2015
    • Hi there
      can anyone help me please,
      I would like to get all the script result in a file
      how can I do it?
1 - 10 of 17 Items