From 077f26c70aa011747f619d8eb7bd1802fc09b7fe Mon Sep 17 00:00:00 2001 From: Raymond Piller Date: Sun, 22 Jul 2018 00:48:36 -0500 Subject: [PATCH] Catch a rogues exception - Showed up in AppVeyor, but never on my dev machine. --- QuserObject/Private/Invoke-Quser.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/QuserObject/Private/Invoke-Quser.ps1 b/QuserObject/Private/Invoke-Quser.ps1 index 7396b45..1add84d 100644 --- a/QuserObject/Private/Invoke-Quser.ps1 +++ b/QuserObject/Private/Invoke-Quser.ps1 @@ -28,7 +28,11 @@ function Invoke-Quser { $quser = if ($Server) { '{0} /SERVER:{1}' -f (Get-Command 'quser').Path, $Server } else { (Get-Command 'quser').Path } Write-Debug "[QuserObject Invoke-Quser] QUSER Command: ${quser}" - $result = (Invoke-Expression $quser) 2>&1 + try { + $result = (Invoke-Expression $quser) 2>&1 + } catch { + $result = $Error[0].Exception.Message + } Write-Verbose "[QuserObject Invoke-Quser] QUSER Result (${LASTEXITCODE}):`n$($result | Out-String)" if ($LASTEXITCODE -eq 0) {