私の新しい雇用主は、何百人ものユーザーのためにフォルダリダイレクトを設定していましたが、それを設定した人は何をしているのかよくわかっていませんでした。その結果、リダイレクトされたフォルダ/ホームディレクトリの権限に関するベストプラクティス従われなかった。
リダイレクトされたフォルダーの場所にユーザーがアクセスできるようにするための解決策は、代わりにルート ディレクトリ (「ホーム」)Full Control
にアクセス許可 (もちろん「共有」アクセス許可ではなく、NTFS アクセス許可) を適用Everyone
し、それをルートの下のすべてのサブフォルダーとファイルに伝播することでした。
何が問題になるでしょうか? CEO が自分のフォルダーに機密情報を持っているわけでも、誰かが CryptoWall に感染して他の人のファイルを暗号化するわけでもありませんMy Documents
。そうですよね?
とにかく、CryptoWall 感染が除去され、バックアップが復元された今、多くの人々が現在の権限をもっと軽いものに置き換えることを望んでおり、私も数百のフォルダーの権限ダイアログをクリックしなくても済むようにしたいと考えています。
PowerShell はどのようにしてこの問題を解決し、人生を再び価値あるものにしてくれるのでしょうか?
答え1
JScottに感謝... クラスやメソッドなど、いくつかの PowerShellを使用してSystem.Security.Principal
、一連のサブフォルダーの ACL をユーザーのホーム ディレクトリに適した ACL に置き換えます。
$Root = "Path to the root folder that holds all the user home directories"
$Paths = Get-ChildItem $Root | Select-Object -Property Name,FullName
$DAAR = New-Object system.security.accesscontrol.filesystemaccessrule("MyDomain\Domain Admins","FullControl","ContainerInherit, ObjectInherit","None","Allow")
#Domain Admin Access Rule.
$SysAR = New-Object system.security.accesscontrol.filesystemaccessrule("SYSTEM","FullControl","ContainerInherit, ObjectInherit","None","Allow")
#SYSTEM Access Rule.
foreach ($Folder in $Paths)
{
Write-Host "Generating ACL for $($folder.FullName) ... "
#For error handling purposes - not all folders will map to a user of the exact same name, this makes them easier to handle when viewing the output.
$ACL = New-Object System.Security.AccessControl.DirectorySecurity
#Creates a blank ACL object to add access rules into, also blanks out the ACL for each iteration of the loop.
$objUser = New-Object System.Security.Principal.NTAccount("MyDomain\"+$folder.name)
#Creating the right type of User Object to feed into our ACL, and populating it with the user whose folder we're currently on.
$UserAR = New-Object system.security.accesscontrol.filesystemaccessrule( $objuser ,"FullControl","ContainerInherit, ObjectInherit","None","Allow")
#Access Rule for the user whose folder we're dealing with during this iteration.
$acl.SetOwner($objUser)
$acl.SetAccessRuleProtection($true, $false)
#Change the inheritance/propagation settings of the folder we're dealing with
$acl.SetAccessRule($UserAR)
$acl.SetAccessRule($DAAR)
$acl.SetAccessRule($SysAR)
Write-Host "Changing ACL on $($folder.FullName) to:"
$acl | fl
#For error handling purposes - not all folders will map to a user of the exact same name, this makes them easier to handle when viewing the output.
Set-Acl -Path $Folder.Fullname -ACLObject $acl
}
答え2
前の回答は機能しませんもしホームフォルダ/リダイレクトフォルダは「ユーザーに排他的権限を与える」で設定されています。このオプションを選択すると推奨されないフォルダーへの権限を持つのはシステムとユーザーのみです。フォルダーの所有権を取得しない限り、権限を変更することはできません (管理者であっても)。
これは、所有権を取得せずにこれを回避する方法です。これは 2 段階のプロセスです。
ICACLS を実行してフォルダーとサブフォルダーの権限を変更する PowerShell スクリプトを作成します。
PSexec を実行して Powershell スクリプトを開始します。
以下より抜粋および改変: https://mypkb.wordpress.com/2008/12/29/how-to-restore-administrators-access-to-redirected-my-documents-folder/
1 PowerShell スクリプトを作成/コピー/盗用する (PS 3.0 以上が必要)
#ChangePermissions.ps1
# CACLS rights are usually
# F = FullControl
# C = Change
# R = Readonly
# W = Write
$StartingDir= "c:\shares\users" ##Path to root of users home dirs
$Principal="domain\username" #or "administrators"
$Permission="F"
$Verify=Read-Host `n "You are about to change permissions on all" `
"files starting at"$StartingDir.ToUpper() `n "for security"`
"principal"$Principal.ToUpper() `
"with new right of"$Permission.ToUpper()"."`n `
"Do you want to continue? [Y,N]"
if ($Verify -eq "Y") {
foreach ($FOLDER in $(Get-ChildItem -path $StartingDir -directory -recurse)) {
$temp = $Folder.fullname
CACLS `"$temp`" /E /P `"${Principal}`":${Permission} >$NULL
#write-host $Folder.FullName
}
}
- PSEXEC を実行すると、SYSTEM アカウントとして動作し、SYSTEM とユーザーのみがアクセスできるフォルダーの権限を変更できます。PSexec をインストールして実行します。https://technet.microsoft.com/ja-jp/sysinternals/bb897553.aspx
コマンドラインから:
psexec -s -i powershell -noexit "& 'C:\Path\To\ChangePermissions.ps1'"