vendredi 22 novembre 2019

If statement in PowerShell cmdlet parameter list

Send-Message `
    -From $emailAuthUser `
    -To $($emailTo -split ',') `
    if($emailCC -ne "NA") { -CC $($emailCC -split ',') } `
    -Subject $emailSubject `
    -Body $emailBody `
    -Attachments $attachments `
    -ReplyTo $($emailReplyTo -split ',') `
    -SmtpServer $emailSmtpServer `
    -Port $emailSmtpPort `
    -Credential $creds `
    -UseSsl

Error: A positional parameter cannot be found that accepts argument 'if'.

Is there an easy way to optionally include a parameter in a "built-in" cmdlet like I am trying to accomplish above? If so, how?

Aucun commentaire:

Enregistrer un commentaire