2017-05-05 99 views
1

從屏幕截圖中可以看到,運行腳本時出現錯誤,但是當我從Write-Host中獲取輸出並粘貼時,它會成功運行,發生了什麼?爲什麼在此Set-MailContact -EmailAddresses行會返回一個錯誤?

對於測試我註釋了New-Mailcontact並在最後加上Write-Host

$CSVpath = Read-Host -Prompt "Enter the path of the contacts .csv" 
Import-Csv "$CSVpath" | ForEach-Object { 
     $name = $_.displayName 
     $proxies = $_.proxyAddresses 
     $proxy = $proxies.replace(";",",") 
     #New-MailContact -ExternalEmailAddress $_.Mail -Name "`"$name`"" -Alias $_.sAMAccountName -DisplayName $name -FirstName $_.givenName -Initials $_.initials -LastName $_.sn 
     Set-MailContact -Identity $_.sAMAccountName -CustomAttribute1 "CreatedWithScript" 
     Set-MailContact -Identity $_.sAMAccountName -CustomAttribute3 $_.extensionAttribute3 
     Set-MailContact -Identity $_.sAMAccountName -EmailAddresses $proxy 
     Write-Host "New contact created: Name="$_.displayName 
     Write-Host "      UPN="$_.userPrincipalName 
     Write-Host Set-MailContact -Identity $_.sAMAccountName -EmailAddresses $proxy 
     } 

ISE Screenshot

回答

0

得到它從Spiceworks還在用戶的工作如下。

我認爲-EmailAddresses參數需要一個字符串數組 而不是一個逗號分隔的字符串。給它這是一個嘗試:

$proxy = $proxies -split ';'

Set-MailContact -Identity $_.sAMAccountName -EmailAddresses $proxy

相關問題