PowerShell & System Center Orchestrator - Best Practice Template HD

31.03.2015
A reusable template for “best practice” execution of PowerShell scripts within a System Center Orchestrator runbook using the built-in “Run .Net Script” activity. This example shows a “best practice” method of executing PowerShell scripts within a System Center Orchestrator runbook using the built-in “Run .Net Script” activity. Using this method provides several benefits to overcome some inherent limitations of Orchestrator’s out-of-the-box PowerShell support: - Uses latest installed version of PowerShell: by default, the Run .Net Script activity runs scripts with PowerShell 2.0, which lacks many features of newer versions. This method will use the latest version installed on the runbook server. - Uses 64-bit process: by default, the Run .Net Script activity runs scripts in a 32-bit process, because Orchestrator is an x86 application. This technique ensures scripts run in native 64-bit PowerShell, which avoids some potential compatibility problems. - Captures detailed logs: keeps a trace log for easier troubleshooting - Allows custom published data: provides any script variable values back to the runbook for continued use - Robust error handling: all errors are caught and handled by the script, with error messages published to the data bus - Semantically-correct result status: allows defining your own success criteria so you can take correct action when something didn’t work as intended, even if the script ran without throwing any exceptions The key to the technique is doing all the “real work” of the script in a separate PowerShell session from the one initially created by Orchestrator. This lets us get into a fancy new 64-bit process with the latest PowerShell version where we can work with minimal risk of unexpected legacy behavior or issues. This is done by running the main script content as a script block using Invoke-Command. Download and documentation available at https://automys.com/library/asset/powershell-system-center-orchestrator-practice-template

Похожие видео