powershell function

Sara 421 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 Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,455 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 45,831 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