Dans cette méthode, j'ai ajouté un paramètre $ blindcopy que je veux être en mesure de permettre aux utilisateurs bcc lorsqu'ils sont appelés. Après avoir testé ce script sans ce paramètre ajouté, tout va bien. Après avoir ajouté cet ajout, je reçois une erreur disant "Impossible de valider l'argument sur le paramètre 'bcc' L'argument est nul ou vide" J'ai essayé d'ajouter l'attribut AllowEmptyString() au paramètre mais toujours pas de chance. Toute aide est très appréciée!Autoriser param à accepter une chaîne vide ou vide 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
Merci pour votre aide! – johnnyjohnson