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