What’s the difference between “Write-Host”, “Write-Output”, or “[console]::WriteLine”?

There are a number of different ways to output messages. What is the effective difference between outputting something via Write-Host, Write-Output, or [console]::WriteLine? I also notice that if I use: write-host “count=” + $count The + gets included in the output. Why’s that? Shouldn’t the expression be evaluated to produce a single concatenated string before … Read more

Array.Add vs +=

I’ve found some interesting behaviour in PowerShell Arrays, namely, if I declare an array as: $array = @() And then try to add items to it using the $array.Add(“item”) method, I receive the following error: Exception calling “Add” with “1” argument(s): “Collection was of a fixed size.” However, if I append items using $array += … Read more

How do I capture the output into a variable from an external process in PowerShell?

I’d like to run an external process and capture it’s command output to a variable in PowerShell. I’m currently using this: $params = “/verify $pc /domain:hosp.uhhg.org” start-process “netdom.exe” $params -WindowStyle Hidden -Wait I’ve confirmed the command is executing but I need to capture the output into a variable. This means I can’t use the -RedirectOutput … Read more