检查用户是否是会员并删除

时间:2019-02-04 07:44:51

标签: powershell active-directory

我需要一个脚本来验证是否有多个用户是AD组列表的成员,如果有,请删除它们。我有这样的东西:

func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
    return self.navigationController ?? self
} 

但是出现以下错误:

Remove-ADGroupMember : Cannot validate argument on parameter 'Identity'. The
argument is null. Provide a valid value for the argument, and then try running
the command again.
At line:12 char:44
+             Remove-ADGroupMember -Identity $group.Name -Members $user.SamAccount ...
+                                            ~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Remove-ADGroupMember], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.RemoveADGroupMember

1 个答案:

答案 0 :(得分:1)

猜测您正在改编一些预先存在的代码,因为该行中的属性未在代码中定义:

Remove-ADGroupMember -Identity $group.Name -Members $user.SamAccountName -Confirm:$false

易于修复,只需将$group.Name更改为$group,还需要将$user.SamAccountName更改为$user

Remove-ADGroupMember -Identity $group -Members $user -Confirm:$false