このメソッドでは、呼び出されたときにbccユーザーにできるようにする$ blindcopyパラメータを追加しました。このパラメータを追加せずにこのスクリプトをテストした後、すべて正常です。この追加を追加した後、 "パラメータ 'bcc'の引数を検証できません。引数がnullまたは空です。" AllowEmptyString()属性をパラメータに追加しようとしましたが、まだ運がありません。どんな助けでも大歓迎です!あなたの関数の-BlindCopy
パラメータが空の文字列を受け入れた場合でもparamにnullまたは空の文字列を受け入れるPowerShell
cls
$BccNull = ""
function SendEmail([string]$BodyString,[string]$SubjectString,[string[]]$EmailRecipientsArray,[string]$FileAttachment=$null,[AllowEmptyString()][string]$BlindCopy)
{
$MethodName = "Send Email"
# Send the HTML Based Email using the information from the tables I have gathered information in
try
{
$user = "[email protected]"
$pass = ConvertTo-SecureString -String "bar" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $user, $pass
$SMTPServer = "some.mail.server"
if([string]::IsNullOrEmpty($BodyString))
{
$BodyString = " Body text was empty for user: $ErrorMessageUserName"
}
if([string]::IsNullOrEmpty($FileAttachment))
{
Send-MailMessage -From "[email protected]" -To "[email protected]" -Subject $SubjectString -Bcc $BlindCopy -Body $BodyString -BodyAsHtml -Priority High -dno onSuccess, onFailure -SmtpServer $SMTPServer -Credential $cred
}
else
{
Send-MailMessage -From "[email protected]" -To "[email protected]" -Subject $SubjectString -Body $BodyString -BodyAsHtml -Attachments $FileAttachment -Priority High -dno onSuccess, onFailure -SmtpServer $SMTPServer -Credential $cred
}
}
catch
{
Write-Host "An Exception has occurred:" -ForegroundColor Red
Write-Host "Exception Type: $($_.Exception.GetType().FullName)" -ForegroundColor Red
Write-Host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red
#$ErrorMessage = "Script Error: "+ $_.Exception.Message + "`n" + "Exception Type: $($_.Exception.GetType().FullName)"
#$SubjectLine = "Script Error: " + $MethodName + " " + $ErrorMessageUserName
#SendEmail -BodyString $ErrorMessage -SubjectString $SubjectLine -EmailRecipientsArray $EmailErrorAddress -FileAttachment $null
$SuccessfulRun = $false
#ReturnStatusError -CurrentStatus "Error" -ErrorMessage $_.Exception.Message
}
}
SendEmail -BodyString "Test" -SubjectString "Test" -EmailRecipientArray "[email protected]" -FileAttachment $null -BlindCopy $BccNull
ありがとうございました! – johnnyjohnson