我要导出文件夹子集的文件夹权限。
Department
中的每个文件夹都有两个子文件夹,Public
和Internal
。
例如,我需要文件夹D:\Data\Department\Science\Public
或D:\Data\Department\Sales\Public
的权限。
$FolderPath = dir -Directory -Path "D:\Data\Department" -Force
$Report = @()
Foreach ($Folder in $FolderPath)
{
$Folder2 = Join-Path -Path $Folder -ChildPath "Public"
$Acl = Get-Acl $Folder2.FullName
foreach ($Access in $acl.Access)
{
$Properties = [ordered]@{'FolderName'=$Folder2.FullName;'AD
Group or User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
$Report += New-Object -TypeName PSObject -Property $Properties
}
}
$Report | Export-Csv -path "C:\Users\adminrw\FolderPermissions.csv"
错误:
Get-Acl : Cannot validate argument on parameter 'Path'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:7 char:16
+ $Acl = Get-Acl $Folder2.FullName
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-Acl], ParameterBindingValidationException
答案 0 :(得分:0)
看起来脚本中的Join-Path正在使用文件夹的名称并将子路径添加到该路径。这导致$Folder2
最终像SomeFolder\Public
尝试使用
$Folder2 = Join-Path -Path $Folder.FullName -ChildPath "Public"
这将使$Folder2
:D:\Data\Department\SomeFolder\Public
答案 1 :(得分:0)
我已更正脚本。请使用以下代码:
$FolderPath = dir -Directory -Path "D:\Data\Department" -Force | Select *
$Report = @()
Foreach ($Folder in $FolderPath)
{
$Folder2 = Join-Path -Path $Folder.FullName -ChildPath "Public"
$Acl = Get-Acl $Folder2
foreach ($Access in $acl.Access)
{
$Properties = [ordered]@{'FolderName'=$Folder2.FullName;'AD
Group or User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
$Report += New-Object -TypeName PSObject -Property $Properties
}
}
$Report | Export-Csv -path "C:\Users\adminrw\FolderPermissions.csv"