Windowsファイルサーバの継承しない設定のフォルダの権限を表示するスクリプト

Windowsファイルサーバの継承しない設定のフォルダの権限を表示するスクリプトを探していたのですが、すごく便利なスクリプトを発見しました。

 

これがあると本当に助かります。

 

ファイルサーバを長く運営していて、困るのが権限の不透明さです。

 

管理者が替わったりするとどんどんとブラックボックス化していき、放置されることになります。

 

また、フォルダのトップから権限を継承している場合は、わかりやすいのですが、途中のサブフォルダで継承しないに設定している場合、権限がその下のフォルダやファイルに付与されないので、ユーザーから閲覧できないとかアクセスできないとか連絡がくることがあります。

 

そこで、便利なのがWindowsファイルサーバの継承しない設定のフォルダの権限を表示するスクリプトです。

 

これがあると、社内で管理しているファイルサーバの継承しない設定がされているフォルダを特定することができるようになります。

 

社内SEをしている方や、インフラエンジニアの方は知っておいて損はない情報だと思います。

 

 

こちら

 

param($TargetPath=  "\\fileserver.contoso.local\share",
$Directory = $true)

Measure-Command{

if($Directory){
$Items=Get-ChildItem $TargetPath -Recurse -Directory
$Ancestor_output = (Join-Path $TargetPath Ancestor.csv)
$error_output = (Join-Path $TargetPath Get-Acl_dir_Error.txt)
}else{
$Items=Get-ChildItem $TargetPath -Recurse
$access_output = (Join-Path $TargetPath FileAccessRights.csv)
$error_output = (Join-Path $TargetPath Get-Acl_file_Error.txt)

}#end of if($Directory)
$error.Clear()
$Ancestor = @()
for($i=0;$i -lt $Items.count;$i++){
$Item = $Items[$i].Fullname
try{
$Acls = Get-Acl $Item
$Access =$Acls.Access[0]
    foreach($Access in $Acls.Access){
        if (-not $Access.IsInherited){
$Row  = "" | Select Path,IdentityReference,FileSystemRights,AccessControlType
        $Row.Path =(Convert-Path $Acls.Path)
        $Row.IdentityReference = $Access.IdentityReference
        $Row.FileSystemRights = $Access.FileSystemRights
        $Row.AccessControlType = $Access.AccessControlType
        

        $Ancestor += $Row

        }
        }                         
}catch{
$Item >> $error_output
$Error[0] >> $error_output
    }
} #End of for($i=0;$i -lt $Items.count;$i++)

$Ancestor |Export-Csv $Ancestor_output -Encoding Default -NoTypeInformation 

} #End of Measure-Command

 

「情報元」

https://gist.github.com/sito74/33fc655cdb50c6c7f9028654bf624d8b#file-get-diraccessancestorcsv-ps1

 

CSVの出力先は随時変更するとさらに使いやすくなります。

 

[マウジー] 鞄 ショルダーバッグ SOUVENIR ショッパー 010FAT51-6400 (ブラック)