假设某个域的pipe理员被激发,并且您现在是Windows 2012服务器的新pipe理员。 在pipe理networking时,有些东西告诉你有些人正在使用具有pipe理权限的本地帐户login到计算机(他们可能从前一个pipe理员那里获得了这个用户)。 现在你想要做的是禁用所有本地pipe理员,除了内置的pipe理员组策略。
我试图改变“允许本地login” :
Computer Configuration * Policies * Windows Settings * Security Settings * Local Policies * User Rights Assignment
但事情是,Windows只允许你这样做,如果你将“pipe理员组”添加到允许的列表中,那么我们将回到原点。
也许你在问错误的问题。 与其试图在一堆不同的计算机上禁用一堆本地用户帐户,或许应该使用组策略中的受限制的组来准确定义允许哪些人成为计算机上的Administrators组的成员。 它将删除所有计算机上本地pipe理员组中的所有帐户,但您指定的帐户(或组)除外。
https://technet.microsoft.com/en-us/library/cc756802(v=ws.10).aspx
但是,如果由于某种原因,您实际上想要将本地用户帐户保留在所有客户端的本地Administrators组中,但只是将其禁用,那么您将不得不开发一个脚本来执行此操作。
编辑:因为这是一个慵懒的周六下午,我写了一个脚本,做你所描述的。 它将禁用除内置pipe理员以外属于pipe理员组的所有用户本地用户帐户。 这不是最有效的方法,但我懒得优化它。 再次,为了logging,我的build议是使用组策略限制组,但我只是想做一些脚本。
# 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() }