PS: Script to Save Share Permissions to a Text File

Specifications:

  1. It creates the log file afresh for every run
  2. Inserts two new lines after every folder ACLs output
  3. Uses Get-ACL
  4. Supports paths with spaces

Script:

$permsLogFile = "C:tempshare-permissions.txt" Write-Output "Start of the script" > $permsLogFile $networkPath = \<servername><sharename>" $subFolders = Get-ChildItem -Name $networkPath foreach ($Folder in $subFolders){ $cmd = ‘Get-Acl "’ + "$networkPath$Folder" + ‘"’ Write-Output "`r`n`r`nRunning Commamnd: $cmd" >> $permsLogFile Invoke-Expression $cmd | Write-Output >> $permsLogFile }

 

Output:

Start of the script

Running Commamnd: Get-Acl "\myserverusersFolder With Spaces"

Directory: \myserverusers

Path             Owner             Access           
—-             —–             ——           
Folder With Spaces          BUILTINAdministrators         NT AUTHORITYSYSTEM Allow FullControl…   

Running Commamnd: Get-Acl "\myserverusersTestUserg"

Directory: \myserverusers

Path             Owner             Access           
—-             —–             ——           
TestUserg            NT AUTHORITYSYSTEM         NT AUTHORITYSYSTEM Allow FullControl…   

 

Requirement: Exporting Network Folder Permissions to Text with Powershell or VBS

Script:

$networkPath = "\<servername><sharename>"
$permsLogFile = "C:tempshare-permissions.txt"
$subFolders = Get-ChildItem $networkPath -Name
foreach ($Folder in $subFolders){
	$cmd = "cacls $networkPath$Folder"
	Write-Output "Running Commamnd: $cmd" >> $permsLogFile
	Invoke-Expression $cmd | Write-Output >> $permsLogFile

}

Output:

Running Commamnd: cacls \myserverusersTestUserg
\myserverusersTestUserg NT AUTHORITYSYSTEM:(OI)(CI)F
           BUILTINAdministrators:(OI)(CI)F
           myserverTestUserg:(OI)(CI)F

Running Commamnd: cacls \myserverusersTestUserh
\myserverusersTestUserh NT AUTHORITYSYSTEM:(OI)(CI)F
           BUILTINAdministrators:(OI)(CI)F
           myserverTestUserh:(OI)(CI)F 

Leave a Reply

Your email address will not be published. Required fields are marked *