Powershell 在Active Directory中创建联系人的脚本无效

Powershell 在Active Directory中创建联系人的脚本无效,powershell,active-directory,contacts,Powershell,Active Directory,Contacts,我正在测试环境中运行一个脚本,在那里它工作得很好 我在生产环境中运行该脚本,但它不起作用 在Windows Server 2008 R2 Standard或Enterprise的控制下,在域控制器上启动时 必须在“-”运算符的右侧提供值表达式。 在C:\Scripts\GalSync.ps1:89 char:14 +$TAGECREDD -语句中间出现了断线,造成了问题。您需要连接这些行 第87行和第89行只能在一行上。像这样: $colContacts = Get-ADObject -Filt

我正在测试环境中运行一个脚本,在那里它工作得很好 我在生产环境中运行该脚本,但它不起作用

在Windows Server 2008 R2 Standard或Enterprise的控制下,在域控制器上启动时

必须在“-”运算符的右侧提供值表达式。 在C:\Scripts\GalSync.ps1:89 char:14
+$TAGECREDD -

语句中间出现了断线,造成了问题。您需要连接这些行

第87行和第89行只能在一行上。像这样:

$colContacts = Get-ADObject -Filter 'objectClass -eq "contact"' -searchbase $targetOU -Server $targetDC -Credential $targetCred -Properties targetAddress
第143行和第145行也是如此。他们应该在一起

    New-ADObject -name $user.displayName -type contact -Path $targetOU -Description $user.description -server $targetDC -credential $targetCred -OtherAttributes $hashAttribs
同样,第155行和第157行也应

    $colContacts = Get-ADObject -Filter $strFilter -searchbase $targetOU -server $targetDC -credential $targetCred -Properties * 
第185行和第187行

    Get-ADObject -Filter $strFilter -searchbase $targetOU -server $targetDC -credential $targetCred | Remove-ADObject -server $targetDC -credential $targetCred -Confirm:$false
第200行和第202行

SyncContacts-sourceDC$DOMAIN_1-sourceUser$USER_1-sourcePWFile$PWFILE_1-targetDC$DOMAIN_2-targetUser$USER_2-targetPWFile$PWFILE_2-TargetTou$OU_CONTACTS_2

第206和208行

SyncContacts-sourceDC$DOMAIN_2-sourceUser$USER_2-sourcePWFile$PWFILE_2-targetDC$DOMAIN_1-targetUser$USER_1-targetPWFile$PWFILE_1-TargetTou$OU_CONTACTS_1

可能还有更多,因此您需要仔细查看脚本中是否有其他无效换行符

致意
Fridden

第89行
$targetCred-Properties targetAddress
完全没有意义。脚本应该在没有第89行的情况下运行?没有第89行的情况下脚本不会工作一元运算符“-”后缺少表达式。在C:\Scripts\GalSync.ps1:145 char:2+-
    Get-ADObject -Filter $strFilter -searchbase $targetOU -server $targetDC -credential $targetCred | Remove-ADObject -server $targetDC -credential $targetCred -Confirm:$false