我是新的powershell下面的脚本,我有它删除所有组从用户成员的标签,除了“域用户”,这工程罚款很多次没有任何问题
从用户中删除组
$list = Import-Csv c:\user\DN.csv
foreach ($entry in $list)
$UserDN = $entry.DistinguishedName
Get-ADGroup -LDAPFilter "(member=$UserDN)" | foreach-object {
if ($_.name -ne "Domain Users") {remove-adgroupmember -identity $_.name -member $UserDN -Confirm:$False}
但问题是,如果此脚本无法从选项卡的用户成员中删除任何组,它将抛出以下错误,但它不会显示无法从哪个用户ID中删除成员身份,因为用户可分辨名称是从CSV文件导入的。
Remove-ADGroupMember : The specified account name is not a member of the group
At C:\User\removegroups.ps1:35 char:115
+ Get-ADGroup -LDAPFilter "(member=$UserDN)" | foreach-object {if ($_.name -ne "Domain Users") {remove-adgroupmember <<
<< -identity $_.name -member $UserDN -Confirm:$False}
+ CategoryInfo : NotSpecified: (xyz:ADGroup) [Remove-ADGroupMember], ADException
+ FullyQualifiedErrorId : The specified account name is not a member of the group,Microsoft.ActiveDirectory.Management.Commands.RemoveADGroupMember
2条答案
按热度按时间zy1mlcev1#
pu3pd22g2#