Wartość właściwości FileSystemRights
jest niepodpisaną 32-bitową liczbą całkowitą, gdzie każdy bit reprezentuje konkretne uprawnienie dostępu. Większość uprawnień jest wymienionych w Win32_ACE
class documentation, z wyjątkiem "ogólnych" uprawnień (bitów 28-31) i prawa dostępu do SACL (bit 23). Więcej szczegółów można znaleźć here i here.
Jeśli chcesz przełamać dostęp maskę ACE do swoich szczególnych praw dostępu (VULGO „rozszerzone uprawnienia”) mógłby zrobić coś takiego:
$accessMask = [ordered]@{
[uint32]'0x80000000' = 'GenericRead'
[uint32]'0x40000000' = 'GenericWrite'
[uint32]'0x20000000' = 'GenericExecute'
[uint32]'0x10000000' = 'GenericAll'
[uint32]'0x02000000' = 'MaximumAllowed'
[uint32]'0x01000000' = 'AccessSystemSecurity'
[uint32]'0x00100000' = 'Synchronize'
[uint32]'0x00080000' = 'WriteOwner'
[uint32]'0x00040000' = 'WriteDAC'
[uint32]'0x00020000' = 'ReadControl'
[uint32]'0x00010000' = 'Delete'
[uint32]'0x00000100' = 'WriteAttributes'
[uint32]'0x00000080' = 'ReadAttributes'
[uint32]'0x00000040' = 'DeleteChild'
[uint32]'0x00000020' = 'Execute/Traverse'
[uint32]'0x00000010' = 'WriteExtendedAttributes'
[uint32]'0x00000008' = 'ReadExtendedAttributes'
[uint32]'0x00000004' = 'AppendData/AddSubdirectory'
[uint32]'0x00000002' = 'WriteData/AddFile'
[uint32]'0x00000001' = 'ReadData/ListDirectory'
}
$fileSystemRights = Get-Acl -LiteralPath 'C:\some\folder_or_file' |
Select-Object -Expand Access |
Select-Object -Expand FileSystemRights -First 1
$permissions = $accessMask.Keys |
Where-Object { $fileSystemRights.value__ -band $_ } |
ForEach-Object { $accessMask[$_] }
prostego uprawnienia FullControl
, Modify
, ReadAndExecute
itp. są tylko określonymi kombinacjami tych rozszerzonych uprawnień. ReadAndExecute
jest na przykład kombinacja z następujących wydłużonych uprawnień:
ReadData/ListDirectory
Execute/Traverse
ReadAttributes
ReadExtendedAttributes
ReadControl
więc maskę dostępu ReadAndExecute
musiałby t on wartość 131241.
Jeśli chcesz rezultatem będzie połączenie prostego zgody, a pozostałe rozszerzone uprawnienia, można zrobić coś takiego:
$accessMask = [ordered]@{
...
}
$simplePermissions = [ordered]@{
[uint32]'0x1f01ff' = 'FullControl'
[uint32]'0x0301bf' = 'Modify'
[uint32]'0x0200a9' = 'ReadAndExecute'
[uint32]'0x02019f' = 'ReadAndWrite'
[uint32]'0x020089' = 'Read'
[uint32]'0x000116' = 'Write'
}
$fileSystemRights = Get-Acl -LiteralPath 'C:\some\folder_or_file' |
Select-Object -Expand Access |
Select-Object -Expand FileSystemRights -First 1
$fsr = $fileSystemRights.value__
$permissions = @()
# get simple permission
$permissions += $simplePermissions.Keys | ForEach-Object {
if (($fsr -band $_) -eq $_) {
$simplePermissions[$_]
$fsr = $fsr -band (-bnot $_)
}
}
# get remaining extended permissions
$permissions += $accessMask.Keys |
Where-Object { $fsr -band $_ } |
ForEach-Object { $accessMask[$_] }
ten powinien mieć więcej upvotes. Świetna sprawa. –
Świetna odpowiedź, chociaż istnieje literówka w '$ fsr = $ fsr -band (-bNOT $ _)'. Zauważ binarny '-bNOT' zamiast logicznego' -not'. – JosefZ
@JosefZ Dzięki za heads up. Naprawiony. –