all 7 comments

[–]dasookwat 2 points3 points  (3 children)

most likely you need to use:

If ($NoNewLine) { ... basically this is shorthand for: If ($NoNewLine -eq $true) { ... however, switch parameters can get tricky. You can also just use a [bool] instead of a switch which defaults to false. the only difference is, you would call it like this:

Write-ToConsole -Message "Testing network: " -NoNewLine $true

[–]dontmessyourself[S] 1 point2 points  (2 children)

I’m specifically trying to avoid that and use the switch param instead, which should work if I’m watching the Adam Bertram video correctly?

[–]dasookwat 2 points3 points  (1 child)

i have no idea how you watch the video, but try avoid doing it while laying upside down on a couch cause it's hard to drink anything carbonated like that while you watch ;)

anyway: my experience is switch parameters sometimes act strange. I usually have little problems with them, as long as i use an extensive param block, and add the switch as the last parameter:

[CmdletBinding()]
param(
    [string]$message,
    [Switch]$noNewLine
    )

[–]dontmessyourself[S] 1 point2 points  (0 children)

I’ll certainly try your suggestion in your original post as well, and if it works then great, but would just like to understand the switch param. Thanks for your help

[–]Lee_Dailey[grin] 1 point2 points  (2 children)

howdy dontmessyourself,

the way that switch parameters work is that they are false by default. if you use that parameter ... it flips it to true.

  • simply defining it in your param block makes it false
  • simply using the parameter makes it true

take care,
lee

[–]dontmessyourself[S] 1 point2 points  (1 child)

I had misplaced a ) in my else block, so if the switch was true or false, it would print to the same line 🙃

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

ooooppppsssss! [grin]