PowerShell Logo Small

Invoke-AsWorkflow



This is the built-in help made by Microsoft for the command 'Invoke-AsWorkflow', in PowerShell version 4 - as retrieved from Windows version 'Microsoft Windows 8.1 Enterprise' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Runs a command or expression as a Windows PowerShell Workflow.

SYNTAX


Invoke-AsWorkflow [-CommandName <String>] [-Parameter <Hashtable>] [<CommonParameters>]
Invoke-AsWorkflow [-Expression <String>] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Invoke-AsWorkflow workflow runs any command or expression as an inline script in a workflow. These workflows use the standard workflow semantics, have all workflo
w common parameters, and have all benefits of workflows, including the ability to stop, resume, and recover.


Workflows are designed for long-running commands that collect critical data, but can be used to run any command. For more information, see about_Workflows.


You can also add workflow common parameters to this command. For more information about workflow common parameters, see about_WorkflowCommonParameters.


This workflow is introduced in Windows PowerShell 3.0.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=287544
New-PSWorkflowExecutionOption
New-PSWorkflowSession
about_Workflows

Windows PowerShell Workflow Module
Windows PowerShell Workflow Utility Module



REMARKS

<

Examples


Example 1: Run a cmdlet as a workflow

PS C:\>Invoke-AsWorkflow -CommandName Get-ExecutionPolicy -PSComputerName (Get-Content Servers.txt)

PSComputerName PSSourceJobInstanceId Value

-------------- --------------------- -----

Server01 77b1cdf8-8226-4662-9067-cd2fa5c3b711 AllSigned

Server02 a33542d7-3cdd-4339-ab99-0e7cd8e59462 Unrestricted

Server03 279bac28-066a-4646-9497-8fcdcfe9757e AllSigned

localhost 0d858009-2cc4-47a4-a2e0-da17dc2883d0 RemoteSigned





This command runs the Get-ExecutionPolicy cmdlet as a workflow on hundreds of computers.

The command uses the CommandName parameter to specify the cmdlet that runs in the workflow. It uses the PSComputerName workflow common parameter to specify the comput
ers on which the command runs. The value of the PSComputerName parameter is a Get-Content command that gets a list of computer names from the Servers.txt file. The pa
rameter value is enclosed in parentheses to direct Windows PowerShell to run the Get-Command command before using the value.

As with all remote commands, if the command runs on the local computer, (if the value of the PSComputerName parameter includes the local computer), you must start Win
dows PowerShell with the "Run as administrator" option.




Example 2: Run a cmdlet with parameters

The first command uses the Import-Csv cmdlet to create an object from the content in the Servers.csv file. The command uses the Header parameter to create a ServerNam
e property for the column that contains the names of the target computers, also known as "remote nodes." The command saves the result in the $s variable.
PS C:\>$s = Import-Csv .\Servers.csv -Header ServerName, ServerID


The second command uses the Invoke-AsWorkflow workflow to run a Get-ExecutionPolicy command on the computers in the Servers.csv file.The command uses the CommandName
parameter of Invoke-AsWorkflow to specify the command to run in the workflow. It uses the Parameter parameter of Invoke-AsWorkflow to specify the Scope parameter of
the Get-ExecutionPolicy cmdlet with a value of Process.The command also uses the PSConnectionRetryCount workflow common parameter to limit the command to five attempt
s on each computer and the PSComputerName workflow common parameter to specify the names of the remote nodes (target computers). The value of the PSComputerName param
eter is an expression that gets the ServerName property of every object in the $s variable.
PS C:\>Invoke-AsWorkflow -CommandName Get-ExecutionPolicy -Parameter @{Scope="Process"} -PSComputerName {$s.ServerName}-PSConnectionRetryCount 5



These commands run a Get-ExecutionPolicy command as a workflow on hundreds of computers. The command uses the Scope parameter of the Get-ExecutionPolicy cmdlet with a
value of Process to get the execution policy in the current session.




Example 3: Run an expression as a workflow

PS C:\>Invoke-AsWorkflow -Expression "ipconfig /all" -PSComputerName (Get-Content DomainControllers.txt) -AsJob -JobName IPConfig

Id Name PSJobTypeName State HasMoreData Location Command

-- ---- ------------- ----- ----------- -------- -------

2 IpConfig PSWorkflowJob Completed True Server01, Server01... Invoke-AsWorkflow



This command uses the Invoke-AsWorkflow workflow to run an Ipconfig command as a workflow job on the computers listed in the DomainControllers.txt file.

The command uses the Expression parameter to specify the expression to run. It uses the PSComputerName workflow common parameter to specify the names of the remote no
des (target computers).

The command also uses the AsJob and JobName workflow common parameters to run the workflow as a background job on each computer with the "Ipconfig" job name.

The command returns a ContainerParentJob object (System.Management.Automation.ContainerParentJob) that contains the workflow jobs on each computer.