Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. $ComputerName = $env:computername
  2. $AllShares = Get-WmiObject -Class win32_share -ComputerName $ComputerName | Select-Object -ExpandProperty Name
  3.  
  4. Function GetShareSecurity
  5. {
  6. Param([string]$path= $(throw"$path required."))
  7. Write-Host "--------------------------------------------------"
  8. $pathparts = $path.split("\")
  9. $ComputerName = $pathparts[2]
  10. $ShareName = $pathparts[3]
  11.  
  12. Write-Host "File Sharing Permissions Report - $path"
  13. $acl = Get-Acl $path
  14.  
  15. Write-Host "File/NTFS Permissions"
  16. foreach($accessRule in $acl.Access)
  17. {
  18. Write-Host " " $accessRule.IdentityReference $accessRule.FileSystemRights
  19. }
  20. Write-Host
  21. Write-Host "Share/SMB Permissions"
  22. $Share = Get-WmiObject win32_LogicalShareSecuritySetting -Filter "name='$ShareName'" -ComputerName $ComputerName
  23. if($Share){
  24. #$obj = @()
  25. $ACLS = $Share.GetSecurityDescriptor().Descriptor.DACL
  26. foreach($ACL in $ACLS){
  27. $User = $ACL.Trustee.Name
  28. if(!($user)){$user = $ACL.Trustee.SID}
  29. $Domain = $ACL.Trustee.Domain
  30. switch($ACL.AccessMask)
  31. {
  32. 2032127 {$Perm = "Full Control"}
  33. 1245631 {$Perm = "Change"}
  34. 1179817 {$Perm = "Read"}
  35. }
  36. Write-Host " $Domain\$user $Perm"
  37. }
  38. }
  39. Write-Host
  40. }
  41.  
  42. foreach ($ShareItem in $AllShares) {
  43. If ($ShareItem -eq "IPC$") {
  44. Write-Host "Default Share for Remote IPC... nothing to do"
  45. } else {
  46. $path = "\\"+$ComputerName+"\"+$ShareItem
  47. GetShareSecurity -path $path
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement