【问题标题】:Error Trying to get-acl from child folders in script尝试从脚本中的子文件夹获取 acl 时出错
【发布时间】:2019-09-09 22:33:58
【问题描述】:

我最近一直在编写此代码,试图仅从共享文件夹中的 ACL 获取所有人和经过身份验证的用户。

脚本确实获取共享并对其进行迭代,但我无法从父文件夹或其子文件夹获取 ACL

另外,我想知道如何导出不使用export-csv 迭代每个共享而不是每个服务器。

尝试使用-Depth 参数,将参数get-childitem 更改为get-item

唯一有效的方法是打开where-object comenting #-like 'Everyone' -or $_.IdentityReference -like 'NT Authority\Authenticated Users' } |

$Server="Server"
$shares = gwmi win32_Share -ComputerName $Server |
  Where-Object {$_.type -eq '0'} | 
  Where {$_.name -notlike "*$*"} | Select-Object -ExpandProperty Name
  $Shares
  foreach ($share in $shares){
$root = "\\$Server\$share"
$csv  = "C:\temp\$Server-$share.csv"
Remove-Item $csv
New-Item $csv
Get-ChildItem -literalPath $root -Recurse -directory |
  ForEach-Object {
    $dir = $_
    ##Test-Path $dir}}
    Get-Acl $dir | Select-Object -Expand Access |
      Where-Object { $_.IdentityReference }|#-like 'Everyone' -or $_.IdentityReference -like 'NT Authority\Authenticated Users' } |
      ForEach-Object {
        New-Object PSObject -Property @{
          Folder       = $dir.FullName
          Access       = $_.FileSystemRights
          Control      = $_.AccessControlType
          User         = $_.IdentityReference
          Inheritance  = $_.IsInherited
          LastModified = $dir.LastWriteTime

        }
      } 
  } | Export-Csv $csv -Force
} 

预期导出到 csv 文件,但我有

Get-Acl:找不到路径“XXXX”,因为它不存在 + 获取 Acl $Dir

【问题讨论】:

    标签: powershell get-childitem


    【解决方案1】:

    你需要在你的条件括号中加上括号:

    Get-Acl $dir | Select-Object -Expand Access |
      Where-Object { ($_.IdentityReference -like 'Everyone') -or ($_.IdentityReference -like 'NT Authority\Authenticated Users') } |
      ForEach-Object {
    

    【讨论】:

      猜你喜欢
      • 2014-02-03
      • 1970-01-01
      • 2017-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多