PowerShell Get-Acl displays an unknown FileSystemRights for certain folders, files, and drives when GENERIC_ALL or other generic rights exist in an ACE
The Get-Acl PowerShell cmdlet is great for getting the NTFS permissions of folders, files, and drives however you may notice some strange behaviour with the FileSystemRights showing an numeric value rather than an enum.
This can occur when GENERIC permissions such as GENERIC_READ, GENERIC_ALL, GENERIC_WRITE, or GENERIC_EXECUTE are in use.
These permission can be seen in the definition of the access mask format
https://learn.microsoft.com/en-us/windows/win32/secauthz/access-mask-format
We came across this problem when writing an update for our Network Documentation Tool XIA Configuration Server please go ahead and take a look at our software.
#
Corrects the NTFS file system rights standardizing GENERIC_* permissions.
Function Get-FileSystemRights
{
[CmdletBinding()]
param(
[Parameter()]
[int] $RightsValue
)
$GENERIC_ALL = [int]268435456;
$GENERIC_READ = [int]-2147483648;
$GENERIC_WRITE = [int]1073741824;
$GENERIC_EXECUTE =[int]536870912;
if (($RightsValue -band $GENERIC_ALL) -eq $GENERIC_ALL) { return [System.Security.AccessControl.FileSystemRights]::FullControl;
}
if (($RightsValue -band $GENERIC_READ) -eq $GENERIC_READ)
{
$RightsValue = $RightsValue -= $GENERIC_READ;
$RightsValue = $RightsValue += [int][System.Security.AccessControl.FileSystemRights]::Read;
$RightsValue = $RightsValue += [int][System.Security.AccessControl.FileSystemRights]::Synchronize;
}
if (($RightsValue -band $GENERIC_WRITE) -eq $GENERIC_WRITE)
{
$RightsValue = $RightsValue -= $GENERIC_WRITE;
$RightsValue = $RightsValue += [int][System.Security.AccessControl.FileSystemRights]::Write;
$RightsValue = $RightsValue += [int][System.Security.AccessControl.FileSystemRights]::Synchronize;
}
if (($RightsValue -band $GENERIC_EXECUTE) -eq $GENERIC_EXECUTE)
{
$RightsValue = $RightsValue -= $GENERIC_EXECUTE;
$RightsValue = $RightsValue += [int][System.Security.AccessControl.FileSystemRights]::Traverse;
$RightsValue = $RightsValue += [int][System.Security.AccessControl.FileSystemRights]::Synchronize;
}
return [System.Security.AccessControl.FileSystemRights] $RightsValue;
}
To function be used as per the following
$acl = (Get-Acl "D:\TestFolder").Access;
foreach ($ace in $acl)
{
Write-Host $ace.IdentityReference $ace.FileSystemRights (Get-FileSystemRights -RightsValue $ace.FileSystemRights);
}
The permissions will be resolved correctly.
Comments
Post a Comment