tl;dr
function SvnUrlExists($url)
{
# Suppress all output streams (external stdout and stderr in this case)
# To suppress stderr output only, use 2>$null
svn info $url *>$null
# For predictable results with external programs,
# infer success from the *process exit code*, not from the automatic $? variable.
# See https://github.com/PowerShell/PowerShell/issues/10512
$LASTEXITCODE -eq 0
}
Your own answer effectively addresses the redirection issue.
Steven Penny's answer proposes *>$null, i.e. suppressing all output streams as a convenient alternative - it obviates the need for Out-Null, which I generally suggest replacing with $null = ... - see this answer.
However, there's another problem with the code in your question:
While it may work with your particular command, $?, unfortunately, is not a robust indicator of whether an external program succeeded or not - use $LASTEXITCODE -eq 0 instead, because - due to a bug as of PowerShell Core 7.0.0-preview.3, reported on GitHub here - $? can end up reflecting $false even when $LASTEXITCODE is 0 (unequivocally signaling success).
- Update: If and when the pre-v7.2 experimental feature named
PSNotApplyErrorActionToStderr becomes an official feature, this problem will go away - see this answer for more information.
As for what you tried in your question:
svn info $url | out-null 2>&1 # WRONG
Only success output is sent through to the pipeline (stdout output from external programs is sent to PowerShell's success output stream).
Redirections such as 2>&1 act on individual commands in a pipeline, not the pipeline as a whole.
Therefore, if svn info $url produces stderr output, it prints straight to the host (console) - Out-Null never sees it.