简体   繁体   English

撤消本地管理员,但不撤消域管理员

[英]Revove local admin but NOT Domain admin

Using this script to remove all local admins from each computer however it also removes domain admins is there a way to do this without removing domain administrators? 使用此脚本从每台计算机上删除所有本地管理员,但是它也删除了域管理员,有没有办法删除域管理员呢?

$remove = net localgroup administrators |
          select -skip 6 |
          ? {$_ -and $_ -notmatch 'successfully|^administrator$'};
foreach ($user in $remove) {
    net localgroup administrators "`"$user`"" /delete
};

Another solution: 另一个解决方案:

Get-LocalGroupMember administrators | 
   Where {$_.name -like "$($env:COMPUTERNAME)\*" -and $_.objectclass -eq "User"} | 
      Remove-LocalGroupMember -Group 'Administrators'

To make it more locale independent you could use SID S-1-5-32-544 instead of a group name. 要使其与语言环境更加独立,可以使用SID S-1-5-32-544代替组名。

Here is one option: 这是一个选择:

Get-LocalGroupMember -Group 'Administrators' | 
    Where-Object Name -notlike '*Domain Admins' |
        Remove-LocalGroupMember -Group 'Administrators'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM