Powershellでフォルダ権限を調査する方法
index
doc
script
adgroup.ps1
function Get-FoldersWithDepth {
param (
[string]$Path,
[int]$Depth
)
if ($Depth -le 0) {
return
}
$folders = Get-ChildItem -Path $Path -Directory
foreach ($folder in $folders) {
Write-Output $folder.FullName
Get-FoldersWithDepth -Path $folder.FullName -Depth ($Depth - 1)
}
}
# 取得したいグループ名
$groupName = "mvd-fjfm_no1"
# 調査開始パスと最大階層
$startPath = "\\mvdfshq1\Shared\MVD-Project"
$maxDepth = 2 # 調査したい階層の深さ
# 指定した階層までのフォルダを取得
$folders = Get-FoldersWithDepth -Path $startPath -Depth $maxDepth
foreach ($folder in $folders) {
# フォルダのアクセス権を取得
$acl = Get-Acl -Path $folder
# アクセス権にグループが含まれているかを確認
foreach ($access in $acl.Access) {
if ($access.IdentityReference -match $groupName) {
# グループが含まれている場合、フォルダのパスを出力
Write-Output $folder
}
}
}