Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ComputerName = $env:computername
- $AllShares = Get-WmiObject -Class win32_share -ComputerName $ComputerName | Select-Object -ExpandProperty Name
- Function GetShareSecurity
- {
- Param([string]$path= $(throw"$path required."))
- Write-Host "--------------------------------------------------"
- $pathparts = $path.split("\")
- $ComputerName = $pathparts[2]
- $ShareName = $pathparts[3]
- Write-Host "File Sharing Permissions Report - $path"
- $acl = Get-Acl $path
- Write-Host "File/NTFS Permissions"
- foreach($accessRule in $acl.Access)
- {
- Write-Host " " $accessRule.IdentityReference $accessRule.FileSystemRights
- }
- Write-Host
- Write-Host "Share/SMB Permissions"
- $Share = Get-WmiObject win32_LogicalShareSecuritySetting -Filter "name='$ShareName'" -ComputerName $ComputerName
- if($Share){
- #$obj = @()
- $ACLS = $Share.GetSecurityDescriptor().Descriptor.DACL
- foreach($ACL in $ACLS){
- $User = $ACL.Trustee.Name
- if(!($user)){$user = $ACL.Trustee.SID}
- $Domain = $ACL.Trustee.Domain
- switch($ACL.AccessMask)
- {
- 2032127 {$Perm = "Full Control"}
- 1245631 {$Perm = "Change"}
- 1179817 {$Perm = "Read"}
- }
- Write-Host " $Domain\$user $Perm"
- }
- }
- Write-Host
- }
- foreach ($ShareItem in $AllShares) {
- If ($ShareItem -eq "IPC$") {
- Write-Host "Default Share for Remote IPC... nothing to do"
- } else {
- $path = "\\"+$ComputerName+"\"+$ShareItem
- GetShareSecurity -path $path
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement