【问题标题】:Powershell Script to loop through folders checking security permissions用于循环检查安全权限的文件夹的 Powershell 脚本
【发布时间】:2014-08-04 03:49:48
【问题描述】:

我有部分代码:目前它在 CSV 文件中为空。但是我需要一个命令来指定要查看的路径/文件夹,我该如何为此目的进行修改。

Param(
    [String]$path,
    [String]$outfile = ".\outfile.csv"
)

$output = @()

ForEach ($item in (Get-ChildItem -Path $path -Recurse -Directory)) {

    ForEach ($acl in ($item.GetAccessControl().Access)){

        $output += $acl | 
            Add-Member `
                -MemberType NoteProperty `
                -Name 'Folder' `
                -Value $item.FullName `
                -PassThru

    }

}

$output | Export-Csv -Path $outfile -NoTypeInformation

【问题讨论】:

  • 我不太清楚你的问题是什么。您已经有一个参数$Path,允许您指定一个基本文件夹。请提供所需结果的示例。
  • 我已经设法通过对脚本进行一些更改来解决它。

标签: security powershell csv permissions acl


【解决方案1】:

好的,让我们这样做。我已经把它变成了一个函数,并删除了它的 OutFile 部分。如果要将其输出到文件,请将其通过管道传输到 Export-CSV。如果要将其保存为变量,请将其分配给变量。这种方式更简单。

Function Get-RecursiveACLs{
Param(
    [String]$Path=$(Throw "You must specify a path")
)

    $Output = GCI $Path -Recurse -Directory|%{
        $PathName=$_.FullName
        $_.GetAccessControl().Access|%{
            Add-Member -InputObject $_ -NotePropertyName "Path" -NotePropertyValue $PathName -PassThru
        }
    }
}

然后将其存储在一个变量中很简单:

$ACLList = Get-RecursiveACLs "C:\Example\Path"

如果您愿意,也可以通过管道将其输出到 CSV:

Get-RecursiveACLs "C:\Example\Path" | Export-CSV "C:\Results.csv" -NoType

将函数放在脚本的顶部并根据需要调用它。

【讨论】:

  • 非常感谢您的回复,我已经用代码解决了。
猜你喜欢
  • 2016-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-17
  • 2019-03-09
  • 1970-01-01
相关资源
最近更新 更多