Saturday, March 5, 2016

Powershell working with Access control list and permission

Param($Server = 'jocket-test-server')
  $ShareSecurity = Get-WmiObject win32_LogicalShareSecuritySetting -ComputerName $Server
  foreach($Share in $ShareSecurity)
  {
    $sharenames = $Share.Name
    $ACLS = $Share.GetSecurityDescriptor().Descriptor.DACL
    foreach($ACL in $ACLS)
    {
    $User = $ACL.Trustee.Name
    switch ($ACL.AccessMask)
      {
      2032127   {$Perm = “Full Control”}
      1245631   {$Perm = “Change”}
      1179817   {$Perm = “Read”}
      }
    $myObj = “” |Select-Object ShareName,User,Permission, NTFS_User, NTFS_Rights
    $myObj.ShareName = $sharenames
    $myObj.User = $User
    $myObj.Permission = $Perm
    $myObj
    }
    }

No comments:

Post a Comment

Thanks for showing interest in tech-jockey.

Content of this blog has been moved to GITHUB

Looking at current trends and to make my content more reachable to people, I am moving all the content of my blog https://tech-jockey.blogsp...