Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Okay, I'm posting as an answer this time, for more flexible formatting, and because I'm confident this will finally solve the problem. ;)</p> <p>Try this:</p> <pre><code>$destinationregex = '(?s)Destination: ([^\r\n]*).*?Start time:' </code></pre> <p>The <code>(?s)</code> means that wildcards can match newline characters. The grouping <code>([^\r\n]*)</code> matches until the end of the line, and the <code>.*?</code> matches the line break. The following would work too:</p> <p><code>$destinationregex = 'Destination: (.*?)\r\nStart time:'</code></p> <p>In fact, since you really only want to match from after "Destination: " to the end of the line, you could just do this, which is the simplest (unless you specifically want to make sure that you only match if "Start time:" is the very next thing):</p> <p><code>$destinationregex = 'Destination: (.*)'</code></p> <p>If it still doesn't work, it may be because $message is being read as an array instead of a string. You can easily test that by adding the debugging line <code>$message.GetType()</code> immediately after setting $message. If it's an array, try setting $message this way (in addition to using one of the regular expressions above):</p> <p><code>$message = $event.message | Out-String</code></p> <p>In fact, doing it this way works in either case, but the <code>| Out-String</code> is superfluous if it's already a string, though it doesn't hurt.</p> <p>For clarity, here's the modified code block, as I <em>think</em> it will end up, depending on the answers to the questions above:</p> <pre><code>foreach ($event in $events) { $message = $event.message | Out-String $destinationregex = 'Destination: (.*)' If ($message -match $destinationregex) { $destination = $matches[1] } else { $destination = "Unknown" } Write-Host $destination } </code></pre>
 

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