Note that there are some explanatory texts on larger screens.

plurals
  1. POPowershell Function runs for each item in array (I don't want this to happen)
    primarykey
    data
    text
    <p>I have created a script to provision Lync users, important details (such as assigned LineURI) for new provisions need to be emailed. Also any errors need to be sent (fluffed up with some friendly error messages of course :)).</p> <p>So I created a few CSVs with all relevant data..</p> <p>Then I created a function:</p> <pre><code>Function Send-Email ($attachArray) { # Get a list of to addresses $toAddresses = "foo@corp.local","bar@corp.local" # Process replacments Replace-EmailMasks # Send conditionaly Switch ($attachArray) { $null { Send-MailMessage -SmtpServer "internalrelay.corp.local" ` -From "test@andylab.local" -To $toAddresses ` -Subject "There should really be something more informative here" ` -BodyAsHTML $SCRIPT:htmlBody } Default { Send-MailMessage -SmtpServer "internalrelay.corp.local" ` -From "test@andylab.local" -To $toAddresses ` -Subject "There should really be something more informative here" ` -BodyAsHTML $SCRIPT:htmlBody -Attachments $attachArray } } } </code></pre> <p>Here's how I invoke it:</p> <pre><code># Logic, then send If (($npSuccess -gt 0) -AND ($errorsExist -gt 0)) { # Attaching both # Heres the summary paragraph $SCRIPT:customSummary = '&lt;p&gt;Success and errors :|&lt;/p&gt;' # Now I'm sending it. Send-Email "$($tempPlace.fullname)\NewProviSsion_Output.csv","$($tempPlace.fullname)\Errors_Output.csv" } ElseIf ($npSuccess -gt 0) {..} # output-generating Success ElseIf ($errorsExist -gt 0) {..} # Failed somewhere Else {..} # no output-generating Success, no overall fails </code></pre> <p>Now this works; Email looks nice, goes to who it should, files attached etc.. </p> <p><strong>Problem</strong> is:<br> For however many files I specify in <em>$attachArray</em>, that's how many emails get sent. The emails are all exactly the same, going to all the same people n many times.</p> <p>It's as if i'm doing this:</p> <pre><code>ForEach ($item in $attachArray) { Send-Email "$($tempPlace.fullname)\NewProviSsion_Output.csv","$($tempPlace.fullname)\Errors_Output.csv" } </code></pre> <p>Except i'm not.. </p> <p>To clarify my objective, I want the email to be sent to all in $toAddresses only <strong>once</strong>.</p> <p>Can anyone enlighten me as to what's going on here?<br> Maybe I've just had a bad Monday morning..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload