Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 获取具有特定ACL的文件夹的名称_Powershell - Fatal编程技术网

Powershell 获取具有特定ACL的文件夹的名称

Powershell 获取具有特定ACL的文件夹的名称,powershell,Powershell,我最近的任务是更新用户主驱动器上的权限结构。我有一个名为home的目录和home下面每个用户的文件夹。主级有两个组,它们被强制下放到每个用户文件夹中。将用户文件夹设置为从其父文件夹继承,然后将用户设置为仅访问其文件夹 我正在尝试编写一个powershell脚本,它将显示是否有任何文件夹留下了特定的ACL。这就是我最终得到的结果,它似乎只是返回指定目录的子文件夹列表,因为我只需要具有指定ACL的文件夹 $path = "\\server\share" $folders = Get-ChildIte

我最近的任务是更新用户主驱动器上的权限结构。我有一个名为home的目录和home下面每个用户的文件夹。主级有两个组,它们被强制下放到每个用户文件夹中。将用户文件夹设置为从其父文件夹继承,然后将用户设置为仅访问其文件夹

我正在尝试编写一个powershell脚本,它将显示是否有任何文件夹留下了特定的ACL。这就是我最终得到的结果,它似乎只是返回指定目录的子文件夹列表,因为我只需要具有指定ACL的文件夹

$path = "\\server\share"
$folders = Get-ChildItem $path | where {$_.psiscontainer}

foreach ($folder in $folders)


{
$domain = "domname"
$aclname = "ACLname"
$aclfullname ="$domain\$aclname"

Get-Acl | select -ExpandProperty Access | where {$_.identityreference -contains $aclfullname}

Write-Host $folder.FullName

}
如果我使用以下命令,它只返回一个结果,但返回ACL而不是文件夹名

$path = "\\node1\home"
$domain = "morgan-cole"
$aclname = "gsherlock"
$aclfullname ="$domain\$aclname"

Get-ChildItem $path | where {$_.psiscontainer} | Get-Acl | select -ExpandProperty Access | where {$_.identityreference -contains $aclfullname}

有什么想法吗?希望我的要求有意义。

这将实现以下目的:

Get-ChildItem $path | where {$_.psiscontainer} | where { $_ | Get-Acl | select -ExpandProperty Access | where {$_.IdentityReference -contains $aclfullname}}
一些解释:

在第二个示例中,您的ACL没有按照您希望的方式工作的原因是,它从管道中的一个文件夹开始,然后被转换为与您要查找的内容相匹配的ACL。但是,它现在已转换为ACL,您希望创建一个文件夹,而不是实际的ACL

因此,“技巧”是将文件夹保留在管道中,但根据ACL过滤文件夹。这是通过在第二个where object子句中嵌套另一个管道来实现的


注:可能有一种方法可以将查找psicontainer的第一部分合并到第二个where子句中,但让我们将其留到另一天。

这将实现以下目的:

Get-ChildItem $path | where {$_.psiscontainer} | where { $_ | Get-Acl | select -ExpandProperty Access | where {$_.IdentityReference -contains $aclfullname}}
一些解释:

在第二个示例中,您的ACL没有按照您希望的方式工作的原因是,它从管道中的一个文件夹开始,然后被转换为与您要查找的内容相匹配的ACL。但是,它现在已转换为ACL,您希望创建一个文件夹,而不是实际的ACL

因此,“技巧”是将文件夹保留在管道中,但根据ACL过滤文件夹。这是通过在第二个where object子句中嵌套另一个管道来实现的


注:可能有一种方法可以将查找psicontainer的第一部分合并到第二个where子句中,但让我们改天再说。

这正是我想要的。非常感谢!正是我想要的。非常感谢!