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
}