【发布时间】:2026-01-15 07:35:01
【问题描述】:
我有一个包含所有要关闭 ACL 的文件夹和文件的数组列表。 一切都在我的 Foreach 循环中运行良好。
但出于一个奇怪的原因,它会抛出:
Get-Acl : 非法字符 + CategoryInfo : NotSpecified: (:) [Get-Acl], ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.GetAclCommand
当我使用“错误”路径运行 get-acl 手册时,我得到了 ACL。 我的代码是:
$ACL = get-acl -LiteralPath "$Path" | select -ExpandProperty access | select IdentityReference
$Result = Compare-Object -ReferenceObject $ACLListAccess -DifferenceObject $ACL -Property Access -PassThru
if ($Result.count -ne 0)
{
$ExplicitTest = get-acl -LiteralPath "$Path" | select -ExpandProperty access
if ($ExplicitTest.IsInherited.count -ne $ACLListAccessFull.count -and $ExplicitTest.IsInherited -Like "*False*")
{
$WrongFolders.Add($Path) | Out-Null
}
}
带有“非法字符”的路径是 \mycompany.com\folders\Algemeen\Reme§ysen
【问题讨论】:
-
检查
$Path在循环中实际扩展为什么。 -
当我写主机时它是正确的。它看起来像在变量本身中以其他方式处理?
标签: powershell acl