我检查了其他帖子,甚至跟随这些帖子,我也无法正常运行。
我正在尝试从驱动器中提取所有ACL信息,但不包括Windows文件夹。
这是我正在使用的代码,但它始终尝试包含该文件夹。有人可以告诉我为什么这不起作用吗?
我也尝试过Where-Object
。
$containers = Get-ChildItem -Path $Path -Recurse -Exclude $exclude |
? {$_.FullName -notmatch '\\windows\\?'}
主要代码:
function Get-PathPermissions {
param ( [Parameter(Mandatory=$true)] [System.String]${Path} )
begin {
$root = Get-Item $Path
($root | Get-Acl).Access |
Add-Member -MemberType NoteProperty -Name "Path" -Value $($root.fullname).ToString() -PassThru
}
process {
$exclude = @('C:\Windows\*')
$containers = Get-ChildItem -Path $Path -Recurse -Exclude $exclude |
? {$_.psIscontainer -eq $true}
if ($containers -eq $null) {break}
foreach ($container in $containers)
{
(Get-Acl $container.FullName).Access |
? { $_.IsInherited -eq $false } |
Add-Member -MemberType NoteProperty -Name "Path" -Value $($container.fullname).ToString() -PassThru
}
}
}
Get-PathPermissions $args[0]
最佳答案
使用-notmatch '\\windows\\?'
进行过滤应该可以。不过,我会使用完整路径来避免潜在的意外排除:
$containers = Get-ChildItem -Path $Path -Recurse |
? { $_.FullName -notmatch '^c:\\windows\\?' -and $_.PSIsContainer}
在PowerShell v3或更高版本上,您还可以使用
-Directory
开关将结果限制为目录:$containers = Get-ChildItem -Path $Path -Recurse -Directory |
? { $_.FullName -notmatch '^c:\\windows\\?' }
关于powershell - Get-ChildItem递归排除不排除文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30934080/