Skip to content

Commit ad85f4d

Browse files
Catch error reading local user with WinRM (#204)
* Wrapped local user read in try-catch * Removed excess whitespace
1 parent 4902b78 commit ad85f4d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

windows/runner.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ if (![System.IO.File]::Exists($SecurePwdFilePath)) {
9797
$secPwd = Get-Content $SecurePwdFilePath | ConvertTo-SecureString
9898
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $secPwd
9999

100-
$env_user = Invoke-Command -ComputerName ([Environment]::MachineName) -Credential $cred -ScriptBlock { $env:USERNAME }
101-
Write-Host "About to execute inventory gathering as user: $env_user"
100+
try {
101+
$env_user = Invoke-Command -ComputerName ([Environment]::MachineName) -Credential $cred -ScriptBlock { $env:USERNAME } -ErrorAction Stop
102+
Write-Host "Executing inventory gathering as user: $env_user..."
103+
} catch [System.Management.Automation.Remoting.PSRemotingTransportException] {
104+
Write-Host "Executing inventory gathering..."
105+
}
102106

103107
# Load the ScriptBlock $ServerStats:
104108
. $ServerStatsPath

0 commit comments

Comments
 (0)