May 19 2021 05:24 AM
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.
May 19 2021 10:16 AM
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>"
May 20 2021 05:25 AM
May 20 2021 01:26 PM
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.
May 21 2021 04:53 AM
May 23 2021 03:35 AM
Also when I run my script, I got an error that I attached.
I running the script with Domain Administrator.