Cloud Management: How to Execute a PowerShell script locally on the MID server instead of on the provisioned VM when launching a stack (during cloud provisioning)Description<!-- div.margin { padding: 10px 40px 40px 30px; } table.tocTable { border: 1px solid; border-color: #e0e0e0; background-color: #fff; } .title { color: #d1232b; font-weight: normal; font-size: 28px; } h1 { color: #d1232b; font-weight: normal; font-size: 21px; margin-bottom: 5px; border-bottom-width: 2px; border-bottom-style: solid; border-bottom-color: #cccccc; } h2 { color: #646464; font-weight: bold; font-size: 18px; } h3 { color: #000000; font-weight: bold; font-size: 16px; } h4 { color: #666666; font-weight: bold; font-size: 15px; } h5 { color: #000000; font-weight: bold; font-size: 13px; } h6 { color: #000000; font-weight: bold; font-size:14px; } ul, ol { margin-left: 0; list-style-position: outside; } --> Description This KB demonstrates how to execute a PowerShell script locally on the MID server instead of on the provisioned VM when launching a stack (during cloud provisioning). Procedure 1> Create a new Cloud APIOpen Cloud Admin Portal > Design > Cloud API > API tab > click on New button, fill in information as below:-Cloud API: any name as required-Interface: Node Access Interface-Product: Node Access-Version: 2.0-Script Type: PowerShell 2> Configure your PowerShell scriptOpen the Cloud API newly created, under CAPI Method Mappers > click on 2.0 link in ExecutePowershellScript row as showing in the screenshot below: Then open the "Request script": This is the PowerShell script that runs locally on MID server. You can either write PowerShell script in this file, e.g. echo 'asdf' > c:\temp\a0.txt Or you can call your own script that's stored on the MID server, e.g. c:\temp\a1.ps1 3> In the Resource Block, add a step to call the API. You can add the step to any resource block. In this example, we have a Test01 Blueprint, so we will go to the resource block that's corresponding to it: Test01 Blueprint Resource. Switch the resource block to Draft mode first, under Operations tab, click on Steps, in Operations drop-down list, select Provision, then click on "Add step" The Add Operation Steps box pops up, fill in information below: -Operation Type: Invoke Cloud API -API Provider: NodeAccess -API Interface: Node Access Interface -API Method: ExecutePowershellScript -CAPI Version: 2.0 4> After the step is added, under Input, fill in any string value for the Parameters. For example: -NodeAddress: 'asdf' -NodeCredential: 'asdf' -Script: 'asdf' -ScriptParameters: 'asdf' *** You can also create Input Parameters and takes values from user's input, for example, create below Step input: -ScriptParameters: ${parameter.PSScriptParameters} Then under "Input Parameters", create below then save. -Name: 'PSScriptParameters' -Datasource: 'Text' -Create Form Parameter: tick TIPS: You can refer to other resource blocks to check how the mapping works. For example, check resource block Virtual Server, then check Input Parameters and Steps of the ExecuteScript operation (this is the OOB operation) NOTE: Once new input parameters are added, please configure it on the Blueprint so it will show up on the form: NOTE: There are four out of the box inputs of the step: NodeAddress, NodeCredential, Script, ScriptParameters These parameters are stored as environmental variables and can be called in the script defined in step 2>. For example, try below script: echo $env:nodeaddress > c:\temp\a01.txt;echo $env:nodecredential > c:\temp\a02.txt;ls env: > c:\temp\a003.txt; 5> Switch the resource block from Draft to Published. Applicable Versions Kingston, London, Madrid Additional Information > In Madrid, when adding operation steps on resource block, a new option is available: Invoke Workflow This option allows you to launch an Orchestration workflow during cloud operations. This is an alternative way to run PowerShell scripts from MID server (using Orchestration Custom PowerShell activity).