I'm printing to a file from within a try/catch block. If an exception is caught, I don't want to print. So I think I'm approaching it wrong. Code:
foreach ($strComputer in $arrComputers){
Try {
“Computer Name:” + $strComputer | out-file "somefile.txt" -append
...something involving Get-WmiObject...
} Catch [System.UnauthorizedAccessException] {
...handle error...
}
}
When that error is caught, I would prefer that "Computer Name:" + $strComputer not print out, as if the try block never happened. How do I accomplish this?