|
PowerShell - Run script |
Declaration
<AMPSHELL PASSWORD="text (encrypted)" USERNAME="text" DOMAIN="text" URI="text" AUTHTYPE="text (options)" ERRORDATASET="text (dataset name)" RESULTDATASET="text (dataset name)" SCRIPT="text" />
Description
Runs an embedded or external Windows PowerShell script locally or on a remote computer. This activity includes an interactive PowerShell editor used for developing, examining and debugging PowerShell scripts.
Practical Usage
Commonly used by IT professionals and power users to control and automate the administration of the Windows operating system and applications that run on Windows.
Parameters
Script
Property | Type | Required | Default | Markup | Description |
---|---|---|---|---|---|
Embedded | Text | No | (Empty) | SCRIPT="embedded script" | If selected, specifies the PowerShell script to run is embedded in the task (selected by default). Enter the script in the provided text box or click the Edit Script button to access the script editor and integrated debugger (an interactive design environment used for developing, examining, and testing PowerShell scripts). If this parameter is selected, the External parameter becomes disabled. |
External | Text | No | (Empty) | FILE="c:\temp\scriptName.ps1 | If selected, specifies the script is located in an external (.ps1) file (disabled by default). Click the Folder icon to navigate to the desired external .ps1 file or manually enter the full path and file name of the file in the provided text box. If this parameter is enabled, the Embedded parameter becomes disabled. |
Output
Property | Type | Required | Default | Markup | Description |
---|---|---|---|---|---|
Create and populate dataset with | Text | No | (Empty) |
|
Specifies the names of the datasets to create and populate with results and errors. The parameters are:
|
Computer
Property | Type | Required | Default | Markup | Description |
---|---|---|---|---|---|
Local computer | --- | --- | --- | --- | If
selected, specifies the PowerShell script runs on the
local computer (selected by default). If
this parameter is enabled, the Another
computer parameter becomes disabled. NOTE: This parameter does not contain markup and is only displayed in visual mode for task construction and configuration purposes. |
Another computer | --- | --- | --- | --- | If
enabled, specifies the PowerShell script runs on another
computer (disabled by default). If
this parameter is selected, the Local
computer parameter becomes disabled and a number of other
parameters become active (as described below). NOTE: This parameter does not contain markup and is only displayed in visual mode for task construction and configuration purposes. |
Uniform resource identifier | Text | Yes, if Another computer is selected | (Empty) | URI="https://host_pc:5986/ | The Uniform Resource Identifier (URI) of the remote computer. URI is a compact string of characters for identifying an abstract or physical resource (for example, https://hostComputer:5986/). This parameter is required if the Another computer parameter is selected. |
Username | Text | Yes, if Another computer is selected | (Empty) | USERNAME="computerUser | A valid username used to log onto the remote computer. This parameter becomes active if the Another computer parameter is selected. |
Domain | Text | Yes, if Another computer is selected | (Empty) | DOMAIN="netauto" | The domain name of the remote computer. This parameter becomes active if the Another computer parameter is selected. |
Password | Text | Yes, if Another computer is selected | (Empty) | PASSWORD="encrypted" | A valid password used to log onto the remote machine. This parameter is required if the Another computer parameter is selected. |
Authentication | Text (options) | Yes, if Another computer is selected | Default |
|
The
type of authentication required for remote connection (if any).
This parameter is active only if the Another
computer parameter is enabled. The available options are:
|
Example
- The sample AML code below can be copied and pasted directly into the Steps Panel of the Task Builder.
- Parameters containing user credentials, files, file paths, and/or other information specific to the task must be customized before the sample code can run successfully.
Description
This sample tasks runs the Get-Service Cmdlet (designed to retrieve information about the services installed on the system) and populate a dataset with results. The dataset is looped, and during each iteration a message dialog displays information about the current service:
- Service Name - %serviceInfo.ServiceName%
- Service Display Name - %serviceInfo.DisplayName%
- Service Type - %serviceInfo.ServiceType%
- Service Status - %serviceInfo.Status%
<AMPOWERSHELL RESULTDATASET="serviceInfo" SCRIPT="Get-Service" />
<AMLOOP ACTIVITY="dataset" DATASET="serviceInfo" />
<AMSHOWDIALOG WINDOWTITLE="SERVICE INFORMATION" BUTTONS="ok_cancel" ONSECONDBUTTONCLICK="stop">Service Name - %serviceInfo.ServiceName%Service Display Name - %serviceInfo.DisplayName%Service Type - %serviceInfo.ServiceType%Service Status - %serviceInfo.Status%</AMSHOWDIALOG>
<AMLOOP ACTIVITY="end" />