を使用して電子メールを送信すると、だから私は手動で$Mail.To = ("[email protected]")
ににメールアドレスを追加する場合は、以下のコードは動作しますが、私はそれを無効にし、Excelの列(mgremail)から引いたら、それはPowerShellの
There must be at least one name or contact group in the To, Cc, or Bcc box.At C:\Users\pshivam\Desktop\Scripts\test.ps1:60 char:5
+ $Mail.Send()
+ ~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
私は、このエラーが発生します
マイコード:
Import-Module ac*
$csv = Import-Csv C:\Users\pshivam\Desktop\Scripts\User.csv
$password = ConvertTo-SecureString -String “Newuser1” -AsPlainText -Force
foreach($item in $csv){
$mgrmail = $item.mgremail
$sam =$item.Username
$displayname = (Get-ADUser $sam -Properties displayname).displayname
##name
$nameTitle = "Name: "
$Name = (Get-ADUser $sam -Properties cn).name
#upn
$upnTitle = "User Logon: "
$UPN = (Get-ADUser $sam -Properties userprincipalname).userprincipalname
$ol = New-Object -comObject Outlook.Application
$mail = $ol.createItem(0)
$Mail.To=($mgrmail)
#$Mail.To=("[email protected]")
$Mail.Subject="TEST"
$Mail.Body = "Hi,
"+ $nameTitle, $displayname, "
" + $upnTitle, $upn + "
TEST
"
$Mail.Send()
}
それはちょうど送る-MailMessage'を '使用するためにはるかに簡単です。 –
空の値をテストする必要があります。 'If(-not $ mgrmail){}' – TheIncorrigible1