Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 将具有Active Directory电子邮件属性的用户添加到包含@abc.com“;_Powershell_Email_Scripting_Automation_Active Directory - Fatal编程技术网

Powershell 将具有Active Directory电子邮件属性的用户添加到包含@abc.com“;

Powershell 将具有Active Directory电子邮件属性的用户添加到包含@abc.com“;,powershell,email,scripting,automation,active-directory,Powershell,Email,Scripting,Automation,Active Directory,我们有票务系统为新加入者创建窗口ID,我们需要根据新用户的电子邮件域将其添加到特定分组 例如,如果用户的电子邮件地址为thomas@abc.com,它将检查电子邮件地址是否包含@abc.com,然后将其添加到测试组;如果用户在组中,请跳过此步骤 $Users = Get-ADUser -Filter * -Properties emailaddress foreach ($user in $Users) { if ($user.emailaddress -match "abc.com"

我们有票务系统为新加入者创建窗口ID,我们需要根据新用户的电子邮件域将其添加到特定分组

例如,如果用户的电子邮件地址为
thomas@abc.com
,它将检查电子邮件地址是否包含
@abc.com
,然后将其添加到
测试组
;如果用户在组中,请跳过此步骤

$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
            }
        }
    }
但在我执行之后,我得到了如下的命中错误

必须在“-”运算符的右侧提供值表达式。
第9行字符:42

表达式或语句中出现意外标记“NotIn”。
第9行字符:43

表达式或语句中出现意外标记“GroupMembers”。
第9行字符:49


非常感谢您事先提供的帮助。

问题是您在代码中使用了
-NotIn
比较运算符。
然而,这个操作员只是,并且不会与您的PoSh版本一起工作


您可以在PowerShell v2.x及更高版本中使用。但是,您需要将支票冲销。使用-NotIn将值与集合进行比较,使用
-NotContains
将集合与值进行比较则相反。

使用哪个版本的PowerShell?PSVersion 2.0@wp78de