powershell - 从 AD 组中删除成员而不使用模块
问题描述
我在不允许在服务器中安装/使用 powershell 模块(如活动目录模块)的环境中工作。
我要做的是删除存储在数组中的组成员。
因此,假设包含要删除的成员的数组称为 tobermoved:
$toberemoved = @("COMPUTER1","COMPUTER2","COMPUTER5")
和组被称为:全球计算机组:
$computergroup = "Global Computer Group"
我试图做的是:
$findgroup=[adsi]"LDAP://$computergroup"
foreach($item in $toberemoved) {
$findgroup.Remove("LDAP://$item")
}
我也试过这个:
$findgroup=[adsi]"LDAP://$computergroup"
foreach($item in $toberemoved) {
$base = "CN=$item,DC=Domain,OU=Computers,OU=local"
$findgroup.Remove("LDAP://$item")
}
没有成功。
尝试在 PowerShell ISE 中运行它时,我得到的是服务器错误。关于可能出错的任何想法,或者在不使用 AD 模块的情况下执行此操作的其他想法?
解决方案
您是否尝试过使用完整的 ADsPath 名称?看看上面写的这篇很棒的文章。https://www.petri.com/managing-active-directory-groups-adsi-powershell
TLDR?
干得好:
[adsi]$Group = "LDAP://CN=GroupName,OU=OrganizationalUnit,DC=Your,DC=Domain,DC=com"
foreach($User in $toberemoved) { #Again, full ADsPaths
$Group.Remove($User)
}
推荐阅读
- scheduler - 元数据调度程序的 Apache Storm 问题
- sql - 如何在where条件下更新多行
- python - 无法使用 chromedriver 调用的模块对象
- ios - 有没有办法在 swiftUI 中设置工作表解雇条件?
- java - 第二次打印储蓄
- jquery - jQuery-AJAX 硬币 API
- reactjs - react codemirror 2如何显示之前输入的变量
- c# - 获取从今天开始 1 个月的日期,UTC,以秒为单位。C#
- vue.js - Eslinter 不适用于具有 .vue 扩展名的文件
- xcode - 在 watch app swift 中应该使用哪种设计模式?