首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Powershell脚本添加具有完全权限的管理员添加没有权限的管理组

Powershell脚本添加具有完全权限的管理员添加没有权限的管理组
EN

Stack Overflow用户
提问于 2021-03-05 02:15:03
回答 1查看 1.1K关注 0票数 0

我们有一个共享驱动器,多年来管理得非常糟糕。给没有理由拥有完全权限的用户提供完全控制。很自然,他们撤掉了管理员,因为“他们不需要看我的东西。”

为了恢复对网络上所有内容的控制,我尝试创建一个Powershell脚本,它将完成两件事:

  1. 最近获得了每个文件夹和文件的所有权
  2. 添加我的默认管理组并给予它完全控制

第一步很有魅力,但是第二步只让我半途而废。我的脚本成功地添加了Admin组,但是它没有提供任何权限。

请原谅这个剧本有多粗糙,这有点像弗兰肯斯坦的怪物,因为我复制了几个不同的脚本,我在网上找到了这样的脚本。

代码语言:javascript
运行
复制
function Recurse-Folder($folderPath, $identity){

 Get-ChildItem $folderPath -Recurse |

 Foreach-Object {
  Take-Ownership $_.FullName $identity 
  }
}


function Take-Ownership($object, $identity) {

 # Give ownership of object to default admin group
 takeown.exe /A /F $object


 # Create new ACL
 $acl = Get-Acl -Path $object
 
 # Set properties
 # $identity = "BUILTIN\Administrators"
 $fileSystemRights= "FullControl"
 $inheritanceFlags = "None"
 $propagationFlags = "None"
 $type = "Allow"
 
 # Create new rule
 $ruleArgs = $identity, $fileSystemRights, $inheritanceFlags, $propagationFlags, $type
 $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($ruleArgs)
 
 # Apply new rule
 $acl.SetAccessRule($rule)

 (Get-Item $object).SetAccessControl($acl)


}


$Path = '\\ShareServer1\Share\'
$identity = 'BUILTIN\Administrators'
# $identity = 'NetAdmin'

Take-OwnerShip $Path $identity
Recurse-Folder $Path $identity


Write-Host
Write-Host Done...
Read-Host
EN

回答 1

Stack Overflow用户

发布于 2021-03-05 05:29:39

$inheritanceFlags = "None"; $propagationFlags = "None" --这意味着您只向$object本身添加权限,而内部没有文件和文件夹。这将导致以下结果(我使用了$identity = 'Everyone'):

我建议您通过GUI手动设置所需的ACL,然后使用(Get-Acl -Path '\\x\share\TestFolder').Access | ? {-not $_.IsInherited}查找正确的Inheritance\Propagation组合。

要在子文件夹或文件上使用Enable inheritance,可以使用$acl.SetAccessRuleProtection($false,$true)$acl.SetAuditRuleProtection($false,$true)。读文档

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66485804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档