Advertisement
kohijones

Untitled

Feb 23rd, 2016
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #requires -Version 2
  2. #requires -PSSnapin Quest.ActiveRoles.ADManagement
  3. function Get-NTFSPermissions {
  4.   [cmdletbinding()]
  5.   param (
  6.     [parameter(mandatory = $true,position = 0,ValueFromPipeline = $true)]$ShareName,
  7.     [parameter(mandatory = $true,position = 1)]$DomainName,
  8.     [parameter(mandatory = $false)][switch]$GroupsOnly
  9.   )
  10.   $Output = @()
  11.   foreach ($Share in $ShareName) {
  12.     $ACLs = Get-Acl -Path $Share
  13.     foreach ($ACL in $ACLs) {
  14.       foreach ($AccessRight in $ACL.Access) {
  15.         if ($AccessRight.IdentityReference -notlike 'BUILTIN\*') {
  16.           $objGroup = [pscustomobject]@{
  17.             'DirectoryPath'  = $Share
  18.             'Identity'       = $AccessRight.IdentityReference
  19.             'SystemRights'   = $AccessRight.FileSystemRights
  20.             'SystemRightsType' = $AccessRight.AccessControlType
  21.             'IsInherited'    = $AccessRight.IsInherited
  22.             'InheritanceFlags' = $AccessRight.InheritanceFlags
  23.             'RulesProtected' = $ACL.AreAccessRulesProtected
  24.           }
  25.         }
  26.         if ($GroupsOnly -eq $true) {$ObjectGroup} else {
  27.           $Groups = $objGroup | Select-Object -ExpandProperty 'Identity' -ErrorAction SilentlyContinue
  28.           foreach ($Group in $Groups) {
  29.             if ($Group -like "$DomainName\*") {
  30.               $grp = $Group.tostring()
  31.               $gp = $grp.replace("$DomainName\",'')
  32.               $Users = Get-QADGroupMember -Identity $gp -ErrorAction SilentlyContinue -SizeLimit 0
  33.               foreach ($User in $Users) {
  34.                 $Usr = $User | Select-Object -ExpandProperty 'samaccountname'
  35.                 $fname = $User | Select-Object -ExpandProperty 'name'
  36.                 $objUser = [pscustomobject]@{
  37.                   'DirectoryPath'  = $Share
  38.                   'Group'          = $gp
  39.                   'SystemRights'   = $objGroup.SystemRights
  40.                   'SystemRightsType' = $objGroup.SystemRightsType
  41.                   'IsInherited'    = $objGroup.IsInherited
  42.                   'InheritanceFlags' = $objGroup.InheritanceFlags
  43.                   'RulesProtected' = $objGroup.RulesProtected
  44.                   'UserName'       = $Usr
  45.                   'Name'           = $fname
  46.                 }
  47.                 $objUser
  48.               }
  49.             }
  50.           }
  51.         }
  52.       }
  53.     }
  54.   }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement