I was in a case where I deleted all the debugs in my code but still got outputs in my terminal when executing my script. All of this is simply after trying to implement a replace on a string.
2 Answers
In this case, you need to set the value of the variable to the desired value in which you are making replacements. The .replace method is only returning a value to the host and will not set the variable which is why your second command is appropriate.
In other situations, you suppress output by piping it to the Out-Null cmdlet like so:
$url.replace('>', ' ') | Out-Null
1 Comment
I just wanted to replaces some chars with spaces in a list of URLs. Here was the code :
$url.replace('>', ' ')
Doing it this way, I got a lot of outputs in my terminal, showing each replaced URLs without me asking for any outputs !
But as you can see here, there is a miss... I'm not assigning the return of this replace. The line should have been :
$url = $url.replace('>', ' ')
And it looks that after assigning it, all the outputs have disappeared.
I don't understand the fundamentals of this behaviour but according to the documentation, this looks actually normal.
As simple as it is, I hope this will save some search time.