PowerShell Workflow Learning-2-workflow running PowerShell commands

Source: Internet
Author: User

Key points:

A) InlineScript activity has active common parameters, but does not have PowerShell common parameters, and commands and expressions in the InlineScript script block do not have workflow capabilities
b) The default InlineScript activity executes in a separate process rather than in the same process as the workflow, but can be controlled using the parameter outofprocessactivity, if the related configuration needs to be deleted or restored InlineScript Activity runs within or outside of a workflow process, see example B
c) variables defined in the workflow are not visible to the commands in the InlineScript script block, unless the $using modifier is used
d) The InlineScript command can change the value of variables imported from the workflow scope, but the changes are not visible in the workflow scope. To make it visible, return the changed value to the workflow scope, using example D

e) PowerShell script (. ps1) needs to run in InlineScript activity

Example B:

#工作流进程内运行PS c:\windows\system32> (get-pssessionconfiguration Microsoft.PowerShell.Workflow). Outofprocessactivityinlinescriptps c:\windows\system32> $o = new-psworkflowexecutionoption-outofprocessactivity "PS c:\windows\system32>set-pssessionconfiguration microsoft.powershell.workflow-sessiontypeoption $o-ForcePS C:\windows\system32> (Get-pssessionconfiguration Microsoft.PowerShell.Workflow). outofprocessactivity# Restore configuration, run PS c:\windows\system32> outside the workflow process (get-pssessionconfiguration Microsoft.PowerShell.Workflow) | Unregister-pssessionconfiguration PS c:\windows\system32> enable-psremoting-forceps C:\Windows\system32> ( Get-pssessionconfiguration Microsoft.PowerShell.Workflow). Outofprocessactivityinlinescript

Example C:

Workflow test-wf4{    $a = 3    inlinescript {"Inline A0 = $a"}    inlinescript {"Inline A1 = $Using: a"}}ps C:\Windows\ system32> test-wf4inline A0 = Inline A1 = 3

Example D:

Workflow test-wf5{    $a = 3    inlinescript {$a = $using: a+1; "Inline a = $a"}    "Workflow a = $a"     $a = inlinescript {$a = $Using: a+1; $a}     "Workflow New a = $a"}   PS C:\Wi ndows\system32> Test-wf5inline A = 4Workflow a = 3Workflow New a = 4

Example e:

Workflow test-wf6{    $ie = InlineScript     {        new-object-comobject internetexplorer.application-property @{ Navigate2= "Www.baidu.com"}    }    $ie. LocationName    } test-wf6ps c:\windows\system32> d:\ untitled 2.ps1 Baidu a bit, you know

PowerShell Workflow Learning-2-workflow running PowerShell commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.