LoginSignup
10
9

More than 1 year has passed since last update.

Powershellでフォルダアクセス権を手軽に確認する

Last updated at Posted at 2021-08-24

注意 本稿はフォルダアクセス権についての記事になります。共有フォルダアクセス権には一切触れません。

Powershellで対象フォルダ/ファイルのアクセス権を確認しようと思ったら、以下のようなコマンドを実行することになると思います。

PS E:\> Get-Acl E:\test

ほいで出力結果が以下のとおりですかね。

    ディレクトリ: E:\


Path   Owner           Access
----   -----           ------
test domain\maganemi   domain/Domain Admin Allow  FullControl.......

おわかりいただけただろうか。
特殊な環境でもなければ、通常はビルトインアカウント(AdministratorやSYSTEMなど)が予め4個程度すでに付与されています。
ところが、実行結果からは一行しか見えていません。
要は改行された先(2つ目の権限以降)の情報がみえていない状態となります。

なので、以下コマンドを実行することでこの問題を解決します。

(get-acl test).Access

上記のように、表示したい項目のみを表示するようコマンドをカッコで囲ってプロパティを指定します。

FileSystemRights  : FullControl
AccessControlType : Allow
IdentityReference : BUILTIN\Administrators
IsInherited       : True
InheritanceFlags  : None
PropagationFlags  : None

FileSystemRights  : 268435456
AccessControlType : Allow
IdentityReference : BUILTIN\Administrators
IsInherited       : True
InheritanceFlags  : ContainerInherit, ObjectInherit
PropagationFlags  : InheritOnly

FileSystemRights  : FullControl
AccessControlType : Allow
IdentityReference : NT AUTHORITY\SYSTEM
IsInherited       : True
InheritanceFlags  : None
PropagationFlags  : None

FileSystemRights  : 268435456
AccessControlType : Allow
IdentityReference : NT AUTHORITY\SYSTEM
IsInherited       : True
InheritanceFlags  : ContainerInherit, ObjectInherit
PropagationFlags  : InheritOnly

FileSystemRights  : Modify, Synchronize
AccessControlType : Allow
IdentityReference : NT AUTHORITY\Authenticated Users
IsInherited       : True
InheritanceFlags  : None
PropagationFlags  : None

あー長い。こうすると権限一覧だけでなく、その他のややこしいプロパティまで全部でてきてしまうんよね。そういうんじゃないんだよ。
もっと絞ります。必要なのは「IdentityReference」だけやからね。

PS E:\> (Get-Acl E:\test).Access | select IdentityReference

ほいで結果がこのような感じですな。

IdentityReference
-----------------
BUILTIN\Administrators
NT AUTHORITY\SYSTEM
NT AUTHORITY\Authenticated Users
BUILTIN\Users

そうよぉ。これよこれ。

コマンドも難しくなく、結果もわかりやすいので非常に使い勝ってよく重宝します。
大量フォルダのアクセス権抽出時にこそ真価を発揮しますな。

foreach ( $FolderList in Get-ChildItem -Path C:\ -Recurse) {(Get-ACL $FolderList).Access | select IdentityReference | -join ($FolderList,",",$_.IdentityReference)}

まぁ利用する機会があるかどうかはわからないけど。私はありました。

以上です。サヨナラ

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9