Forum Discussion

dannytveria's avatar
dannytveria
Brass Contributor
May 19, 2021

Share & NTFS permissions export

Hi,

I need to export a report from my file server for all the share & NTFS permissions to csv file.

I found the next script:

$FolderPath = dir -Directory -Path "#Requested Folder path" -Recurse -Force
$Report = @()
Foreach ($Folder in $FolderPath) {
$Acl = Get-Acl -Path $Folder.FullName
foreach ($Access in $acl.Access)
{
$Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD
Group or
User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
$Report += New-Object -TypeName PSObject -Property $Properties
}
}
$Report | Export-Csv -path "#Report Export path"

 

with this script, I got only the NTFS permissions.

I need to combine also the share permissions to the same CSV file.

thanks for the help.

  • Josh977's avatar
    Josh977
    Copper Contributor

    dannytveria 

    You're going to need to use a combination of Get-SmbShare and Get-SmbShareAccess

    This is also PowerShell version dependent.

     

     

    $cSession = New-CimSession -ComputerName "server" -Credential (get-credential)
    $Results = Get-SmbShare -CimSession $cSession | Get-SmbShareAccess
    
    $cSession | Remove-CimSession
    
    $Results | Export-CSV -Path "<pathToCSVFile>"

     

    • dannytveria's avatar
      dannytveria
      Brass Contributor
      Hi Josh,
      if you can help me, I need Share & NTFS permissions for specific folders.
      I didn`t understand your script
      • Josh977's avatar
        Josh977
        Copper Contributor

        dannytveria 

         

        Share permissions are a function of the SMB share which is a separate entity to windows.  Even though a folder's properties page has a "sharing tab," all it does is allow you to create SMB entities connected to a particular folder.

         

        Thus you need to use the other CmdLts to access SMB shares. 

        Get-SMBShare allows you to get all smb shares on a computer.

        Get-SMBShareAccess get's you the share permissions for each share.

        New-CimSession/Remove-Cimsession is used in case you want to get the data from a remove server.

Resources