이 메서드에서는 매개 변수 $ blindcopy를 추가하여 호출 할 때 bcc 사용자가 가능하도록하고 싶습니다. 이 매개 변수를 추가하지 않고이 스크립트를 테스트하면 모두 정상입니다. 이 추가를 추가 한 후에 "매개 변수 '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