# mulesoft Microsoft Windows PowerShell Connector - Full Documentation --- product: Microsoft Windows PowerShell Connector version: 2.1 is-latest-version: true --- # Microsoft Windows PowerShell Connector > For the full documentation index, see: https://docs.mulesoft.com/llms.txt Microsoft Windows PowerShell Connector Version 2.1 Anypoint Connector for Microsoft Windows PowerShell (PowerShell Connector) enables you to integrate Windows administration tasks into Mule applications. PowerShell Connector enables you to connect to any machine, local or remote, to execute script files and commands on those machines. You can use SSH to execute PowerShell scripts on a remote Windows or Linux (Ubuntu) machine and have the result processed within Mule runtime engine (Mule). > [!NOTE] The connector does not support executing a PowerShell script on a MacOS computer. For information about compatibility and fixed issues, see [Microsoft Powershell Connector Release Notes](https://docs.mulesoft.com/release-notes/connector/microsoft-powershell-connector-release-notes-mule-4). ## Before You Begin To use this connector, you must be familiar with: - Anypoint Connectors - Mule runtime engine (Mule) - Elements in a Mule flow - Global elements - How to create a Mule app using Anypoint Studio To work with PowerShell Connector, you must first install an SSH server on a Windows or Linux (Ubuntu) remote machine: - Windows 1. Download [OpenSSH for Win32 or Win64](https://github.com/PowerShell/Win32-OpenSSH/releases). 2. Follow the [OpenSSH installation steps](https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH). - Linux (Ubuntu) 1. Follow the [SSH installation steps](https://ubuntu.com/server/docs/). 2. Follow [install PowerShell on Linux](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-6) from Microsoft. ## Add a POM File Dependency ```xml com.mulesoft.connectors mule-powershell-connector x.x.x mule-plugin ``` Verify that the connector `version` corresponds to the one you are using. To obtain the most up-to-date `pom.xml` file information: 1. Go to [Anypoint Exchange](https://www.mulesoft.com/exchange/). 2. In Exchange, click **Login** and supply your Anypoint Platform username and password. 3. In Exchange, search for `hdfs`. 4. Click **Dependency Snippets**. ## Add the Connector in Studio Add PowerShell Connector to a Mule project to automatically populate the XML code with the connector’s namespace and schema location, as well as add the required dependencies to the project’s `pom.xml` file. 1. In Anypoint Studio, from the main menu, select **File > New > Mule Project**. 2. Enter a name for your Mule project, and click **Finish**. 3. In the **Mule Palette** view, click **(X) Search in Exchange**. 4. In **Add Modules to Project**, type `powershell` in the search field. 5. Click the name of the connector in **Available modules**. 6. Click **Add**. 7. Click **Finish**. Adding a connector to a Mule project in Studio does not make that same connector available to other projects in your Studio workspace. ### Configure a Global Element in Studio 1. In Studio, click the **Global Elements** tab at the bottom of the canvas. 2. In the **Global Configuration Elements** screen, click **Create**: ![Choose Global Type window with list of configurations](/mulesoft/current/en-us/windows-powershell-connector/latest/_images/microsoft-powershell-config-global-wizard.png) 3. In the **Choose Global Type** wizard, expand **Connector Configuration**, select either **Windows Configuration** or **Linux Configuration**, and click **OK**. This selection enables you to connect remotely to the type of operating system that you choose. 4. Configure the parameters as follows:
ParameterDescription

Connection

Connection type: Windows or Linux

IP Address

IP address of the machine on which you want to execute the script file or command

Username

User associated with the Windows or Linux machine

Password

Password associated with the user name

In the previous image, the placeholder values refer to a configuration file `mule-artifact.properties` placed in the `src/main/resources` folder of your project. You can enter your credentials in the global configuration properties, or you can reference a configuration file that contains those values. To simplify maintenance and improve project reusability, of your project, use a configuration file. Keeping these values in a separate file is useful if you need to deploy to different environments, such as production, development, and QA, where your access credentials differ. See [Anypoint Connector Configuration](https://docs.mulesoft.com/connectors/introduction/intro-connector-configuration-overview) for more information. 5. Keep the **Advanced** tab default values. 6. Click **Test Connection**. 7. Click **OK**. 8. Your configuration should look like this: ![Global element properties window with Windows configuration](/mulesoft/current/en-us/windows-powershell-connector/latest/_images/microsoft-powershell-config.png) ## Next Step After you configure the PowerShell Connector, see the [Examples](https://docs.mulesoft.com/windows-powershell-connector/latest/microsoft-powershell-connector-examples) topic for more configuration information. ## See Also - [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors) - [Anypoint Connector Configuration](https://docs.mulesoft.com/connectors/introduction/intro-connector-configuration-overview) - [Using Anypoint Studio to Configure a Connector](https://docs.mulesoft.com/connectors/introduction/intro-config-use-studio) - [Microsoft Windows PowerShell Connector](https://www.mulesoft.com/exchange/com.mulesoft.connectors/mule-powershell-connector/) - [OpenSSH for Windows](https://github.com/PowerShell/Win32-OpenSSH/releases#) - [OpenSSH installation steps](https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH) - [Linux install SSH](https://documentation.ubuntu.com/server/) - [Salesforce Help](https://help.salesforce.com) --- product: Microsoft Windows PowerShell Connector version: 2.1 is-latest-version: true --- # Microsoft Windows PowerShell Connector Examples > For the full documentation index, see: https://docs.mulesoft.com/llms.txt ## Execute a Command on a Remote Windows Machine In this example, the Mule flow executes a command on a remote Windows machine: ![Flow with Listener, Execute command, and Logger](/mulesoft/current/en-us/windows-powershell-connector/latest/_images/microsoft-powershell-execute-command.png) 1. Create a new Mule project in Anypoint Studio. 2. Add the following properties to the `mule-artifact.properties` file to store your PowerShell credentials: ```text config.host= config.username= config.password= ``` 3. Place the properties file in the project’s `src/main/resources` directory. 4. Drag an **HTTP > Listener** component onto the canvas and configure the following parameters: ![Listener configuration values in properties window](/mulesoft/current/en-us/windows-powershell-connector/latest/_images/microsoft-powershell-http-props.png) 5. Create a configuration for the HTTP Listener if you do not already have one: 1. Click the plus sign (+) on the right side of **Connector Configuration** to add a new HTTP Listener configuration. 2. Enter the following values: - **Host**: `localhost` - **Port**: `8081` 3. Click **OK**. 6. In the **General** section, for **Path**, enter `/executecommand`. 7. Drag the **Execute command** operation of the PowerShell Connector next to the HTTP Listener component. 8. Add a new PowerShell global element to configure the PowerShell Connector: 1. Click the plus sign (+) on the right side of the **Connector Configuration** field. 2. Configure the global element: - Name The name for the configuration - IP Address The IP address of the machine on which to execute your script file or command - Username The name of the user associated with the machine on which to execute your script file or command - Password The password for the user Your configuration should look like this: ![Global element properties window for Windows configuration](/mulesoft/current/en-us/windows-powershell-connector/latest/_images/microsoft-powershell-config.png) The corresponding XML configuration is: ```xml ``` 9. Click **Test Connection**. 10. If the test is successful, click **OK**; if not, review and correct any incorrect parameters and test the connection again. 11. In the **General** properties editor of the PowerShell **Execute command** operation, configure the remaining parameters: - Display Name The name to display for the Execute command operation - Command The command to execute on the remote or local machine: ![Execute command operation properties window](/mulesoft/current/en-us/windows-powershell-connector/latest/_images/microsoft-powershell-execute-command-props.png) 12. Verify that your XML looks like this: ```xml ``` 13. In **Mule Palette > Core**, select **Logger** and then drag it to the canvas after the **Execute command** operation. 14. Configure **Logger**: 1. Enter a display name for the Logger component. 2. For **Message**, enter `#[payload]` so the Mule log message comes from the payload. 3. Set **Level** to `INFO`: ![Logger properties window](/mulesoft/current/en-us/windows-powershell-connector/latest/_images/microsoft-powershell-logger-props.png) 15. Click **File > Save**. 16. Right-click the project in Package Explorer and click **Run As > Mule Application**. 17. Open a browser and validate the response after entering the URL `http://localhost:8081/executecommand`. You should see the output of the **Execute command** operation in the browser and the Studio console. ## Execute a Script File In this example, you create a Mule flow that executes a script file: ![Flow with Listener, Parse Template, Execute script file, and Logger](/mulesoft/current/en-us/windows-powershell-connector/latest/_images/microsoft-powershell-execute-script-file-flow.png) To create the Mule flow: 1. Drag an **HTTP Listener** component onto the canvas and enter `Listener` for **Display Name**: ![Listener configuration values in properties window](/mulesoft/current/en-us/windows-powershell-connector/latest/_images/microsoft-powershell-http-execute-script-file.png) 2. Create a configuration for the **HTTP Listener**: This is required if you have not already done so. 1. Click the plus sign (+) to add a new HTTP Listener configuration. 2. Enter the following values: - **Host**: `localhost` - **Port**: `8081` 3. Click **OK**. 3. In the **General** section, for **Path**, enter `/executescriptfile`. 4. In the `/src/main/resources` folder, create a new file named `get-en-param.ps1`, with the following content: $logFile = "C:\\Windows\\Temp\\log.txt" Add-Content $logFile -Value "Parameter a is $a" Add-Content $logFile -Value "Parameter b is $b" Add-Content $logFile -Value "Parameter c is $c" Write-Host "Parameters received are $a $b $c" 5. Drag a **Parse template** component next to the HTTP Listener. 6. Configure the following parameters: ![Parse Template configuration values in properties window](/mulesoft/current/en-us/windows-powershell-connector/latest/_images/microsoft-powershell-parse-template-props.png) 1. Enter a display name for the **Parse template** component. 2. Enter the location of the `get-en-param.ps1` file. The XML reference should look similar to this: ```xml ``` 7. Drag the **Execute script file** operation of the PowerShell Connector next to the **Parse template** component. 8. In the **General** properties editor of the PowerShell **Execute script file** operation, configure the remaining parameters: 1. Enter the display name for the **Execute script file** operation. 2. In **General > File content**, enter `#[payload]` so that the file that contains the script comes from the payload file. 3. If your script requires parameters, add the parameters for each key and value pair: ![\["Execute script file operation configuration values in properties window"](/mulesoft/current/en-us/windows-powershell-connector/latest/_images/microsoft-powershell-execute-script-file.png) 9. Add a **Logger** component after the **Execute script file** operation to display output in the Studio console, and configure the logger: 1. In the **General** tab, enter a display name for the Logger component. 2. For **Message**, enter `#[payload]` so the Mule log message comes from the payload. 3. Set **Level** to `INFO`. ![Logger properties window](/mulesoft/current/en-us/windows-powershell-connector/latest/_images/microsoft-powershell-logger-props.png) 10. Click **File > Save**. 11. In **Package Explorer**, right-click the project and then click **Run As > Mule Application**. 12. Open a browser and validate the response after entering the URL `http://localhost:8081/executescriptfile`. You should see the operation’s output in the browser and the console. ## Mule XML Flow The XML for your Mule flow should look similar to this: ```xml ``` ## See Also - [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors) - [Anypoint Connector Configuration](https://docs.mulesoft.com/connectors/introduction/intro-connector-configuration-overview) - [Using Anypoint Studio to Configure a Connector](https://docs.mulesoft.com/connectors/introduction/intro-config-use-studio) - [Microsoft Windows PowerShell Connector](https://www.mulesoft.com/exchange/com.mulesoft.connectors/mule-powershell-connector/) - [OpenSSH for Windows](https://github.com/PowerShell/Win32-OpenSSH/releases#) - [OpenSSH Installation Steps](https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH) - [Linux Install SSH](https://ubuntu.com/server/docs/) - [Salesforce Help](https://help.salesforce.com) --- product: Microsoft Windows PowerShell Connector version: 2.1 is-latest-version: true --- # Microsoft Windows PowerShell Connector Reference > For the full documentation index, see: https://docs.mulesoft.com/llms.txt Microsoft Windows PowerShell Connector v2.1 For information about compatibility and fixed issues, see [Microsoft Powershell Connector Release Notes](https://docs.mulesoft.com/release-notes/connector/microsoft-powershell-connector-release-notes-mule-4) ## Configuration ### Parameters
NameTypeDescriptionDefault ValueRequired

Name

String

The name for this configuration. Connectors reference the configuration with this name.

x

Connection

  • Linux Configuration

  • Windows Configuration

The connection types that can be provided to this configuration.

x

Expiration Policy

ExpirationPolicy

Configures the minimum amount of time that a dynamic configuration instance can remain idle before the runtime considers it eligible for expiration. This does not mean that the platform expires the instance at the exact moment that it becomes eligible. The runtime purges instances as it sees fit.

## Connection Types ### Linux Configuration #### Parameters
NameTypeDescriptionDefault ValueRequired

IPAddress

String

Host used to initialize the session.

x

UserName

String

Username used to initialize the session. The value for this field, can be, for example: username or username@domain

x

Password

String

Password used to authenticate the user.

x

Reconnection

Reconnection

When the application is deployed, a connectivity test is performed on all connectors. If set to true, deployment fails if the test doesn’t pass after exhausting the associated reconnection strategy.

### Windows Configuration #### Parameters
NameTypeDescriptionDefault ValueRequired

IPAddress

String

Host used to initialize the session.

x

UserName

String

Username used to initialize the session. The value for this field, can be, for example: username or username@domain

x

Password

String

Password used to authenticate the user.

x

Reconnection

Reconnection

When the application is deployed, a connectivity test is performed on all connectors. If set to true, deployment fails if the test doesn’t pass after exhausting the associated reconnection strategy

## Operations - [Execute Command](#executeCommand) - [Execute Script File](#executeScriptFile) - [Execute Command (exception handling enabled)](#executeCommandExceptionHandlingEnabled) - [Execute Script File (exception handling enabled)](#executeScriptFileExceptionHandlingEnabled) ## Execute Command `` This operation executes the command on the machine. ### Parameters
NameTypeDescriptionDefault ValueRequired

Configuration

String

The name of the configuration to use.

x

Command

String

The command to execute on the client machine.

x

Target Variable

String

Name of the variable that stores the operation’s output.

Target Value

String

Expression that evaluates the operation’s output. The expression outcome is stored in the target variable.

#[payload]

Reconnection Strategy

  • reconnect

  • reconnect-forever

A retry strategy in case of connectivity errors

### Output
TypeString
### For Configurations - config ### Throws - POWERSHELL:RETRY\_EXHAUSTED - POWERSHELL:CONNECTIVITY ## Execute Script File `` This operation executes the script file. ### Parameters
NameTypeDescriptionDefault ValueRequired

Configuration

String

The name of the configuration to use.

x

File Content

Binary

The file which contains the script.

#[payload]

Parameters

Object

The Parameters for the Script.

Target Variable

String

The name of a variable on which the operation’s output is placed.

Target Value

String

An expression to evaluate against the operation’s output. The outcome of that expression is stored in the target variable.

` #[payload]`

Reconnection Strategy

  • reconnect

  • reconnect-forever

A retry strategy in case of connectivity errors.

### Output
TypeString
### For Configurations - config ### Throws - POWERSHELL:RETRY\_EXHAUSTED - POWERSHELL:CONNECTIVITY ## Execute Command (exception handling enabled) `` This operation executes the command on the machine and throws execution related exceptions, if any. ### Parameters
NameTypeDescriptionDefault ValueRequired

Configuration

String

The name of the configuration to use.

x

Command

String

The command to execute on the client machine.

x

Target Variable

String

Name of the variable that stores the operation’s output.

Target Value

String

Expression that evaluates the operation’s output. The expression outcome is stored in the target variable.

#[payload]

Reconnection Strategy

  • reconnect

  • reconnect-forever

A retry strategy in case of connectivity errors

### Output
TypeString
### For Configurations - config ### Throws - POWERSHELL:RETRY\_EXHAUSTED - POWERSHELL:CONNECTIVITY - POWERSHELL:EXECUTION\_EXCEPTION ## Execute Script File (exception handling enabled) `` This operation executes the script file on the target machine and throws execution related exceptions, if any. ### Parameters
NameTypeDescriptionDefault ValueRequired

Configuration

String

The name of the configuration to use.

x

File Content

Binary

The file which contains the script.

#[payload]

Parameters

Object

The parameters for the script.

Target Variable

String

The name of a variable on which the operation’s output is placed.

Target Value

String

An expression to evaluate against the operation’s output. The outcome of that expression is stored in the target variable.

` #[payload]`

Reconnection Strategy

  • reconnect

  • reconnect-forever

A retry strategy in case of connectivity errors.

### Output
TypeString
### For Configurations - config ### Throws - POWERSHELL:RETRY\_EXHAUSTED - POWERSHELL:CONNECTIVITY - POWERSHELL:EXECUTION\_EXCEPTION ## Types ### Reconnection
FieldTypeDescriptionDefault ValueRequired

Fails Deployment

Boolean

When the application is deployed, a connectivity test is performed on all connectors. If set to true, deployment fails if the test doesn’t pass after exhausting the associated reconnection strategy.

Reconnection Strategy

  • reconnect

  • reconnect-forever

The reconnection strategy to use.

### Reconnect
FieldTypeDescriptionDefault ValueRequired

Frequency

Number

How often to reconnect (in milliseconds).

Count

Number

The number of reconnection attempts to make.

blocking

Boolean

If false, the reconnection strategy runs in a separate, non-blocking thread.

true

### Reconnect Forever
FieldTypeDescriptionDefault ValueRequired

Frequency

Number

How often in milliseconds to reconnect.

blocking

Boolean

If false, the reconnection strategy runs in a separate, non-blocking thread.

true

### Expiration Policy
FieldTypeDescriptionDefault ValueRequired

Max Idle Time

Number

A scalar time value for the maximum amount of time a dynamic configuration instance should be allowed to be idle before it’s considered eligible for expiration.

Time Unit

Enumeration, one of:

  • NANOSECONDS

  • MICROSECONDS

  • MILLISECONDS

  • SECONDS

  • MINUTES

  • HOURS

  • DAYS

A time unit that qualifies the maxIdleTime attribute.

## See Also [Salesforce Help](https://help.salesforce.com)