Ima*_*eri 5 active-directory windows-server-2012
假设某个域的管理员被解雇,而您现在是 Windows 2012 服务器的新管理员。在管理网络时,有些信息会告诉您,有些人正在使用具有管理权限的本地帐户登录计算机(他们可能从以前的管理员那里获得了这些用户)。现在您要做的是禁用所有本地管理员,除了内置管理员组策略。
我试图在以下位置更改“允许本地登录”:
Computer Configuration
* Policies
* Windows Settings
* Security Settings
* Local Policies
* User Rights Assignment
Run Code Online (Sandbox Code Playgroud)
但问题是,如果您将“管理员组”添加到允许列表中,Windows 只允许您执行此操作,并且通过这样做,我们将回到原点。
也许你问错了问题。与其尝试在一堆不同的计算机上禁用一堆本地用户帐户,不如改为使用组策略中的受限组来准确定义允许谁成为计算机上管理员组的成员。它将删除所有计算机上本地管理员组中的所有帐户,除了您指定的帐户(或组)。
https://technet.microsoft.com/en-us/library/cc756802(v=ws.10).aspx
但是,如果出于某种原因,您确实希望将本地用户帐户保留在所有客户端的本地管理员组中,而只是禁用它们,那么您将必须开发一个脚本来执行此操作。
编辑:因为这是一个慵懒的星期六下午,我写了一个脚本来完成你所描述的。它禁用除内置管理员之外的所有属于管理员组成员的用户本地用户帐户。这不是最有效的方式,但我懒得优化它。同样,为了记录,我的建议是使用组策略受限组,但我只是想做一些脚本。
# Author: Ryan Ries
# This script disables all local user accounts who are members of the Administrators group,
# except for the built-in Administrator (sid-500).
# Use at your own risk.
Set-StrictMode -Version Latest
[Int]$DomainRole = (Get-WmiObject Win32_ComputerSystem).DomainRole
# Don't run if we are a domain controller.
If (($DomainRole -EQ 4) -OR ($DomainRole -EQ 5))
{
Write-Error "This script cannot be run on a domain controller."
Return
}
# We need to be an elevated administrator.
$CurrentUser = New-Object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())
If (-Not($CurrentUser.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)))
{
Write-Error "$($CurrentUser.Identity.Name) is not currently an Administrator. (Need UAC elevation?)"
Return
}
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ContextType = [System.DirectoryServices.AccountManagement.ContextType]::Machine
$Context = New-Object System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $ContextType, $Env:COMPUTERNAME
$IDType = [System.DirectoryServices.AccountManagement.IdentityType]::SamAccountName
$Group = [System.DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity($Context, $IDType, 'Administrators')
Foreach ($Member In $Group.Members)
{
If ($Member.Sid.Value.EndsWith('-500'))
{
# This is the built-in local administrator, so we'll skip it.
Continue
}
$User = [ADSI]"WinNT://./$($Member.SamAccountName)"
$User.UserFlags = 2
$User.CommitChanges()
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1824 次 |
最近记录: |