windows 将组“Everyone”添加到目录及其所有子目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4464467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add group "Everyone" to directory and all of it's sub-directories
提问by tempid
I'm currently using Vista 32-bit. How do I add the Windows security group "Everyone" and give full control to a directory and all of it's sub-directories and all files? Is there a powershell script that I could use?
我目前使用的是 Vista 32 位。如何添加 Windows 安全组“Everyone”并完全控制目录及其所有子目录和所有文件?是否有我可以使用的 powershell 脚本?
Thanks!
谢谢!
回答by tempid
I've expanded on martona's snippet and was able to give access to all folders and sub-folders. Here's my code -
我已经扩展了 martona 的代码段,并且能够访问所有文件夹和子文件夹。这是我的代码 -
$FilesAndFolders = gci "c:\data" -recurse | % {$_.FullName}
foreach($FileAndFolder in $FilesAndFolders)
{
#using get-item instead because some of the folders have '[' or ']' character and Powershell throws exception trying to do a get-acl or set-acl on them.
$item = gi -literalpath $FileAndFolder
$acl = $item.GetAccessControl()
$permission = "Everyone","FullControl","Allow"
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($rule)
$item.SetAccessControl($acl)
}
回答by martona
$acl = Get-Acl c:\mydir
$permission = "Everyone","FullControl","Allow"
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($rule)
$acl | Set-Acl c:\mydir
回答by Keith Hill
Sometimes the "native" PowerShell way isn't necessarily the best way. For something like this I would still use icacls.exe. Remember that good ol' exes work pretty good in PowerShell. Just cd to the directory you want to set and execute:
有时,“本机”PowerShell 方式不一定是最好的方式。对于这样的事情,我仍然会使用 icacls.exe。请记住,好的 ol' exe 在 PowerShell 中运行良好。只需 cd 到您要设置的目录并执行:
icacls $pwd /grant "Everyone":(OI)(CI)F
This will give Everyone full access to the current directory downwards (via permission inheritance). This should work as long as there are no explicit denials to Everyone in the dir structure.
这将使每个人都可以向下访问当前目录(通过权限继承)。只要 dir 结构中没有对 Everyone 的明确拒绝,这应该有效。