我们有一个共享驱动器,多年来管理得非常糟糕。给没有理由拥有完全权限的用户提供完全控制。很自然,他们撤掉了管理员,因为“他们不需要看我的东西。”
为了恢复对网络上所有内容的控制,我尝试创建一个Powershell脚本,它将完成两件事:
第一步很有魅力,但是第二步只让我半途而废。我的脚本成功地添加了Admin组,但是它没有提供任何权限。
请原谅这个剧本有多粗糙,这有点像弗兰肯斯坦的怪物,因为我复制了几个不同的脚本,我在网上找到了这样的脚本。
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
发布于 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)
。读文档。
https://stackoverflow.com/questions/66485804
复制相似问题