Skip to content

Commit

Permalink
Added error trapping when attepting to get the last exit code from a …
Browse files Browse the repository at this point in the history
…remote machine. Microsoft does not allow you to retrieve information from remote computers due to security and architecture.
  • Loading branch information
Bob Pokorny committed Apr 17, 2024
1 parent 4b7b26e commit 3eb72af
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions IISU/ClientPSCertStoreManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,18 @@ public JobResult ImportPFXFile(string filePath, string privateKeyPassword, strin
// Invoke the script
var results = ps.Invoke();

//Get the last exist code returned from the script
int lastExitCode = (int)(ps.Runspace.SessionStateProxy.PSVariable.GetValue("c"));
// Get the last exist code returned from the script
// This statement is in a try/catch block because PSVariable.GetValue() is not a valid method on a remote PS Session and throws an exception.
// Due to security reasons and Windows architecture, retreiving values from a remote system is not supported.
int lastExitCode = 0;
try
{
lastExitCode = (int)ps.Runspace.SessionStateProxy.PSVariable.GetValue("c");
}
catch (Exception)
{
}


bool isError = false;
if (lastExitCode != 0)
Expand Down

0 comments on commit 3eb72af

Please sign in to comment.