将具有Active Directory电子邮件属性的用户添加到包含" @ abc.com"的组中。

时间:2018-04-10 02:47:52

标签: powershell email scripting automation active-directory

我们有票务系统为新加入者创建窗口ID,我们需要将新用户添加到特定分组,具体取决于他们的电子邮件域。

例如,如果用户的电子邮件地址为@abc.com,则会检查电子邮件地址是否包含test_group,然后将其添加到$Users = Get-ADUser -Filter * -Properties emailaddress foreach ($user in $Users) { if ($user.emailaddress -match "abc.com") { $GroupMembers = Get-ADGroupMember -Identity "test_group" | Select -ExpandProperty SamAccountName if ($User.SamAccountName -NotIn $GroupMembers) { Add-ADGroupMember -Identity "test_group" -Members $User } } } ;如果组中的用户,请跳过此步骤。

func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
    let indexPath = IndexPath(item: self.currendIndex, section: 0)

    DispatchQueue.main.async(execute: {() -> Void in
        self.collectionView.reloadItems(at: [indexPath])
    })
}

但是在我执行之后,我遇到了如下命中错误

  

您必须在' - '的右侧提供值表达式。运营商。
  在线:9字符:42

     

意外的令牌' NotIn'在表达或陈述中   在行:9 char:43

     

意外的令牌' GroupMembers'在表达或陈述中   在线:9字符:49

非常感谢您提前提供帮助。

1 个答案:

答案 0 :(得分:1)

问题是您在代码中使用XmlSerializer比较运算符 但是,此运算符仅为introduced in PowerShell 3,并且不适用于您的PoSh版本。

您可以在PowerShell v2.x及更高版本中使用-NotContains。但是,您需要反转支票。使用-NotIn将值与集合进行比较,使用-NotIn通过将集合与值进行比较来执行相反的操作。