/
PowerShell Command

PowerShell Command

In this article

Overview

You can use PowerShell Command Snap to execute the PowerShell commands.

Snap Type

The PowerShell Command Snap is a Write Snap that executes a windows powershell command.

Prerequisites

  • Windows operating system (typically Windows 10 or later) which includes PowerShell pre-installed, and the required permissions(execution policy) to allow script execution.

Support for Ultra Pipelines  

Snap Views

Type

Format

Number of Views

Examples of Upstream and Downstream Snaps

Description

Type

Format

Number of Views

Examples of Upstream and Downstream Snaps

Description

Input 

Document

 

  • Min: 0

  • Max: 1

  • Mapper

  • Copy

Each document contains data in JSON format.

Output

Document

 

  • Min: 0

  • Max: 1

  • JSON Generator

  • Mapper

Each document contains corresponding response in JSON format.

Error

Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter when running the pipeline by choosing one of the following options from the When errors occur list under the Views tab:

  • Stop Pipeline Execution: Stops the current pipeline execution if the Snap encounters an error.

  • Discard Error Data and Continue: Ignores the error, discards that record, and continues with the remaining records.

  • Route Error Data to Error View: Routes the error data to an error view without stopping the Snap execution.

Learn more about Error handling in Pipelines.

Snap Settings

  • Expression : JavaScript syntax to access SnapLogic Expressions to set field values dynamically (if enabled). If disabled, you can provide a static value. Learn more.

  • SnapGPT : Generates SnapLogic Expressions based on natural language using SnapGPT. Learn more.

  • Suggestion : Populates a list of values dynamically based on your Account configuration.

  • Upload : Uploads files. Learn more.

Learn more about the icons in the Snap Settings dialog.

Field Name

Field Type

Description

Field Name

Field Type

Description

Label*

 

Default Value: PowerShell Command
Example: PowerShell Command Snap

String

The name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your pipeline.

 

Launch As

 

Default Value
Example:

String/Expression

Shall be used to run specific tools and programs with different permissions than the user's current logon provides. %1 is the username and %2 password. For Ex: psexec -u %1 -p %2

Source Script*

String/Expression

Script in SLDB to copy on GroundPlex. Use he Fileicon to select the script. For ex: shared/CreateAccount.ps1

Dest Script Path*

String/Expression

Absolute path where script shall be placed on GroundPlex. For ex: C:/PowershellScript/CreateAccount.ps1

Cmd to Execute*

String/Expression

Command that shall be executed. For ex: powershell.exe C:/PowershellScript/CreateAccount.ps1

Is output JSON?

String/Expression

Check box. If selected, the snap will consider the command output in JSON format , otherwise in String
format.

Snap Execution

Default Value
Example: Execute Only

Dropdown list

Select one of the following three modes in which the Snap executes:

  • Validate & Execute: Performs limited execution of the Snap based on Preview Document Count value in User settings and generates a data preview during pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during pipeline runtime.

  • Execute only: Performs full execution of the Snap during pipeline execution without generating preview data.

  • Disabled: Disables the Snap and all Snaps that are downstream from it.

Examples

Executing the PowerShell script in the Windows PowerShell and writing the output to a JSON file

We can execute the PowerShell script and save the output to a binary file. This example demonstrates how to use the PowerShell command snap to accomplish this task.

First, we need to write a PowerShell script to a file, upload it to SLDB, and configure it to the setting Source Script in the snap.

Set the values in other settings.

Sample PowerShell script

The script file (script.ps1) will contain the following code.

$output = @(
"Hello from PowerShell Script!"
"Tuesday, February 4, 2025 12:17:43 PM"
)
$output | ConvertTo-Json

image-20250207-084152.png

Upon validation, we see the following output in the Snap’s preview.

 

image-20250210-082006.png

 

Next, we configure the JSON Formatter & File Writer snaps to format and write it as JSON binary data into a file.

Also, find a few samples of Powershell scripts below.

1) The script file will contain the code Write-Host "Hello, World!" which will print the output below.

image-20250210-102635.png
  1. The script file will contain the following code which will open the calculator window.

Invoke-Item c:\windows\system32\calc.exe

Download this Pipeline. 

Downloads

  1. Download and import the pipeline into the SnapLogic application.

  2. Configure Snap accounts, as applicable.

  3. Provide pipeline parameters, as applicable.

 

  File Modified

File Powershell Execute Script Example_2025_02_07.slp

Feb 07, 2025 by satya prasad padmanabhuni

Snap Pack History

PowershellSnap Snap Pack

Related Content