Friday, November 2, 2018
List Folders a given user have access
# List Folders a given user have access, check the log file like Get_Folder_Permissions_20181102_035121_result.log
#Usage: .\Get_Folder_Permissions.ps1 "*Path*" "*User*"
param(
[String]$Root = $( throw 'credentialIdentity is required' ),
[String]$User= $( throw 'credentialIdentity is required' )
)
$timeStamp =(Get-Date).tostring("yyyyMMdd_hhmmss")
$logFile ="Get_Folder_Permissions_"+$timeStamp+".log"
$resultFile ="Get_Folder_Permissions_"+$timeStamp+"_result.log"
# Get computer name with Domain
Write-Output "ComputerName: $env:COMPUTERNAME.$env:USERDNSDOMAIN" | Tee-Object -file $logFile -Append
#Write-Output "$(Get-Date -Format "yyyy-MM-dd hh:mm:ss") Server: $env:COMPUTERNAME.$env:USERDNSDOMAIN" | Out-file $logFile -Force
#Get-WmiObject Win32_ComputerSystem
Write-Output "Root= $Root, User=$User"| Tee-Object -file $logFile -Append
#get all groups that a user is a member of
(New-Object System.DirectoryServices.DirectorySearcher("(&(objectCategory=User)(samAccountName=$($User)))")).FindOne().GetDirectoryEntry().memberOf | Tee-Object -file $resultFile -Append
#loop through all subfolders that a user have access
foreach($item in Get-ChildItem $Root -Recurse | where-object {($_.PsIsContainer)})
{
Write-Output $item.FullName | Tee-Object -file $logFile -Append
(Get-Acl $item.FullName).Access | ?{(($_.IdentityReference -match $User)-and (-not $_.IsInherited ))} | Select $item.FullName, IdentityReference,FileSystemRights,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags | Tee-Object -file $resultFile -Append
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment