powershell function

Sara 441 Reputation points
2020-08-28T15:03:56.657+00:00

21130-pow.txt

How to define a small function on the above script(line 33) to easily loop through the servers on an error using try/catch to go back and look at the server again for any errors.Any suggestions is highly appreciated

Windows for business Windows Server User experience PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2020-08-28T18:54:38.357+00:00

    You're running a script block on a remote machine and the code is returning a PSCustomObject. Have the Catch block modify a variable with a distinctive value (e.g. "failure"), and have the Try block modify that same variable with something like "success". Add that value to the PSCustomObject and also add the name of the server to the PSCustomObject, then have the invoking script run the Invoke-Command again for each server that recoded a failure.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.