Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.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_Powershell_Active Directory - Fatal编程技术网

Powershell 将电子邮件地址导入Active Directory

Powershell 将电子邮件地址导入Active Directory,powershell,active-directory,Powershell,Active Directory,我正在尝试导入一个CSV文件,该文件将在我们的广告环境中使用正确的电子邮件地址更新用户 CSV的前几行如下所示: Email,Name adam.lambert@domain.com,Adam Lambert aaron.smith@domain.com,Aaron Smith arthur.aardvark@domain.com,Arthur Aardvark Import-Module ActiveDirectory $data = Import-CSV -Path "C:\Users\r

我正在尝试导入一个CSV文件,该文件将在我们的广告环境中使用正确的电子邮件地址更新用户

CSV的前几行如下所示:

Email,Name
adam.lambert@domain.com,Adam Lambert
aaron.smith@domain.com,Aaron Smith
arthur.aardvark@domain.com,Arthur Aardvark
Import-Module ActiveDirectory
$data = Import-CSV -Path "C:\Users\redacted\Desktop\importtest.csv"
Foreach ($user in $data){
Get-ADUser -Filter “Name -eq ‘$($user.Name)'” | Set-ADUser -Replace @{mail = “$($user.Email)”}
}
我编写的PowerShell脚本如下所示:

Email,Name
adam.lambert@domain.com,Adam Lambert
aaron.smith@domain.com,Aaron Smith
arthur.aardvark@domain.com,Arthur Aardvark
Import-Module ActiveDirectory
$data = Import-CSV -Path "C:\Users\redacted\Desktop\importtest.csv"
Foreach ($user in $data){
Get-ADUser -Filter “Name -eq ‘$($user.Name)'” | Set-ADUser -Replace @{mail = “$($user.Email)”}
}
然而,令我沮丧的是,它不起作用。为了澄清,我正在尝试将“name”(而不是SamAccountName)的ADSI值与Excel中的列表相匹配,事实上我知道这是完全匹配的

有什么想法吗?错误如下:

Get-ADUser : Error parsing query: 'Name -eq ‘Adam Lambert'' Error Message: 'syntax error' at position: '10'.
At line:4 char:11
+ Get-ADUser <<<<  -Filter “Name -eq ‘$($user.Name)'” | Set-ADUser -Replace @{mail = “$($user.Email)”}
    + CategoryInfo          : ParserError: (:) [Get-ADUser], ADFilterParsingException
    + FullyQualifiedErrorId : Error parsing query: 'Name -eq ‘Adam Lambert'' Error Message: 'syntax error' at position: '10'. 
   ,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Get ADUser:分析查询时出错:“Name-eq”Adam Lambert“”错误消息:“syntax Error”位于位置:“10”。
第4行字符:11

+获得ADUser我想你在这条线上有一个倒勾:

难道不是:

"Name -eq '$($user.Name)'"

你这里的代码到处都是“智能引号”。这是因为您从Word或其他东西复制/粘贴了它,还是您的真实代码中有它们?请确保您的代码使用标准的双引号
和单引号
。这正是问题所在。感谢您的解决方案:)实际上是一个“智能引号”(请参见上面的评论)。但这肯定解决了问题。谢谢大家!