我正在尝试运行以下脚本以获取共享驱动器上所有文件权限的报告:
$FolderPath = Get-ChildItem -Directory -Path "\\cst-fileserver\Company" -Recurse -Force
$Output = @()
ForEach ($Folder in $FolderPath) { $Acl = Get-Acl -Path $Folder.FullName
ForEach ($Access in $Acl.Access) {
$Properties = [ordered]@{'Folder Name'=$Folder.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
$Output += New-Object -TypeName PSObject -Property $Properties
}
} $Output | Out-GridView } $Report | Export-Csv -path "C:\new\FolderPermissions.csv"`
尝试此操作时出现以下错误,我对 powershell 还很陌生,所以不确定如何最好地解决这个问题。
Get-ChildItem : Could not find a part of the path 'D:\\shares\\Company\\2MPTRegulatory\\REGULATORY\\PLPI\\PLPI GRANTED\\MPT\\0883 COO(0168) Pulmicort Turbohaler 200 PL\\0883 Granted docs - take
effect from 19-06-18\\CST0168 archive\\0168 Pulmicort Turbohaler 200 PL\\sample scans-checks\\CST0168 Polish Pulmicort Turbuhaler 200ug 100doses (90x38x38) 23.06.2014'.
At line:1 char:15
+ ... olderPath = Get-ChildItem -Directory -Path "D:\\shares" -Recurse -Forc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ReadError: (D:\\shares\\Compa...x38) 23.06.2014:String) \[Get-ChildItem\], DirectoryNotFoundException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : Could not find a part of the path 'D:\\shares\\Company\\2MPTRegulatory\\REGULATORY\\PLPI\\PLPI GRANTED\\MPT\\0883 COO(0168) Pulmicort Turbohaler 200 PL\\0883 Granted docs - take
effect from 19-06-18\\CST0168 archive\\0168 Pulmicort Turbohaler 200 PL\\sample scans-checks\\CST0168 Polish Pulmicort Turbuhaler 200ug 100doses (BUYER) 23.09.2015'.
At line:1 char:15
+ ... olderPath = Get-ChildItem -Directory -Path "D:\\shares" -Recurse -Forc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ReadError: (D:\\shares\\Compa...YER) 23.09.2015:String) \[Get-ChildItem\], DirectoryNotFoundException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : Could not find a part of the path 'D:\\shares\\Company\\2MPTRegulatory\\REGULATORY\\PLPI\\PLPI GRANTED\\MPT\\0883 COO(0168) Pulmicort Turbohaler 200 PL\\0883 Granted docs - take
effect from 19-06-18\\CST0168 archive\\0168 Pulmicort Turbohaler 200 PL\\sample scans-checks\\CST0168 Pulmicort Turbohaler 200mcg 100 doses PL(88x38x38) 26.10.16'.
At line:1 char:15
+ ... olderPath = Get-ChildItem -Directory -Path "D:\\shares" -Recurse -Forc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ReadError: (D:\\shares\\Compa...38x38) 26.10.16:String) \[Get-ChildItem\], DirectoryNotFoundException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
那些文件名路径太长 windows.
这取决于一点,但你通常可以用更长的路径名格式来解决这个问题:
\\?\
像:
Get-ChildItem -Directory -Path '\\?\D:\shares\Company\'
# Or for network paths:
Get-ChildItem -Directory -Path '\\?\UNC\cst-fileserver\Company'
它适用于 powershell 和
Get-Acl
但请注意,某些软件仍然不允许那么长的路径