Suppressing output by piping to Out-Null but then I lose the object?

Good Afternoon,

I am trying to suppress the output of a command so I was piping it to ‘Out-Null’ but I lose the object by doing this so the variable I assign the command to is null.

$dstSite = Connect-Site -Url $row.OneDriveURL -Credential $Credentials | Out-Null

If I run the above then $dstSite is null. Can I allow the object to still exist (and be assigned to $dstSite) but just not show output, I have also tried > $null but I guess this does the same thing and actually deletes the return value altogether.


You may add a comment to their site SG:Desktop Connect Site. It seems like this non Microsoft cmdlet does not behave like a Microsoft cmdlet. :wink: :smiley:

Have a look at Tee-Object

It may be one of the other streams you want to redirect. See about Redirection - PowerShell | Microsoft Docs

# hide error stream
get-childitem foo 2> $null

Redirect all the streams,
eg:- Get-Process *> $Null

But he needs stream #1

$a = Get-Process 2>$null 3>$null 4>$null 5>$null 6>$null

Thanks for the replies, I guess it does not behave like a typical Microsoft cmdlet. I will also try piping to Tee-Object and specifying an output file as that looks promising.