Skip to content

Instantly share code, notes, and snippets.

@jllwebgit
Created December 6, 2015 04:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jllwebgit/2b15d12b6c084b6b83ce to your computer and use it in GitHub Desktop.
Save jllwebgit/2b15d12b6c084b6b83ce to your computer and use it in GitHub Desktop.
$array = New-Object System.Collections.ArrayList
#アクセス権一覧を取得するパス
$targetDir = "C:\"
#結果を出力するCSVパス
$exportCSVPath = "D:\acl.csv"
#全てのサブディレクトリのみ
#ファイルも出力したい場合には、「 Where { $_.PSIsContainer } |」を
#削除する
Get-ChildItem -Recurse -Path $targetDir | Where { $_.PSIsContainer } |
forEach {
$objPath = $_.FullName
$coLACL = Get-Acl -Path $objPath
forEach ( $objACL in $colACL ) {
forEach ( $accessRight in $objACL.Access ) {
$array.add($objPath + "," + `
$accessRight.IdentityReference + "," + `
$accessRight.FileSystemRights + "," + `
$accessRight.AccessControlType + "," + `
$accessRight.IsInherited + "," + `
$accessRight.InheritanceFlags + "," + `
$objACL.AreAccessRulesProtected `
)
}
}
}
#リストをソート
$array.Sort()
#1行目に項目をInsert
$array.insert(0,"Path,`
IdentityReference,`
FileSystemRights,`
AccessControlType,`
IsInherited,`
InheritanceFlags,`
AreAccessRulesProtected"`
)
$array > $exportCSVPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment