Giá trị của thuộc tính FileSystemRights
là số nguyên 32 bit không dấu, trong đó mỗi bit đại diện cho quyền truy cập cụ thể. Hầu hết các điều khoản được liệt kê trong Win32_ACE
class documentation, ngoại trừ các quyền "chung" (bit 28-31) và quyền truy cập SACL (bit 23). Bạn có thể tìm thêm chi tiết here và here.
Nếu bạn muốn phá vỡ một mặt nạ truy cập ACE vào quyền truy cập cụ thể của nó (vulgo "quyền truy cập mở rộng"), bạn có thể làm một cái gì đó như thế này:
$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[$_] }
Các điều khoản đơn giản FullControl
, Modify
, ReadAndExecute
vv chỉ là sự kết hợp cụ thể của các quyền mở rộng này. ReadAndExecute
ví dụ là sự kết hợp của các điều khoản mở rộng sau:
ReadData/ListDirectory
Execute/Traverse
ReadAttributes
ReadExtendedAttributes
ReadControl
để mặt nạ truy cập cho ReadAndExecute
sẽ có t ông đánh giá cao 131241.
Nếu bạn muốn kết quả là một sự kết hợp của phép đơn giản và cho phép mở rộng còn lại, bạn có thể làm một cái gì đó như thế này:
$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[$_] }
Nguồn
2015-01-20 10:07:14
này nên có nhiều upvotes. Công cụ tuyệt vời. –
Câu trả lời tuyệt vời mặc dù có một lỗi đánh máy trong '$ fsr = $ fsr -band (-bNOT $ _)'. Lưu ý nhị phân '-bNOT' thay vì logic' -không'. – JosefZ
@JosefZ Cảm ơn những người đứng đầu. Đã sửa. –