Run Powershell Script

PowerShell is a cross-platform task automation framework. It is built on top of the .NET Common Language Runtime (CLR), and accepts and returns .NET objects.

 

Input Arguments

 

0

File Path or Embedded File

Powershell Script Path

The path to the powershell script to execute.

1

String

Script Arguments (optional)

Optional script arguments to pass to the execut- ing program.

2

Boolean

Wait for Program Completion

Indicates whether the MP should pause until the

program finishes.

Return Arguments

 

3

Integer

Process Exit Code

The powershell script exit code.

 

Returned Status

 

SUCCESS

The program was executed successfully.

FAILURE

The program could not be found or executed.

Remarks

One example of how to use a powershell script is as follows: “Run Powershell Script” which can be used to execute the following script (as an example).

ExportTo-ExcelPDF.ps1

if ($args.Count -gt 0)

{

$path = $args[0]

$xlFixedFormat = “Microsoft.Office.Interop.Excel.xlFixedFormatType” -as [type]

$excelFiles = Get-ChildItem -Path $path -include *.xls, *.xlsx -recurse

$objExcel = New-Object -ComObject excel.application

$objExcel.visible = $false foreach($wb in $excelFiles)

{

$filepath = Join-Path -Path $path -ChildPath ($wb.BaseName + “.pdf ”)

$workbook = $objExcel.workbooks.open($wb.fullname, 3)

$workbook.Saved = $true “saving $filepath”

$workbook.ExportAsFixedFormat($xlFixedFormat::xlTypePDF, $filepath)

$objExcel.Workbooks.close()

}

$objExcel.Quit()

}

The first argument of the MP command must be the full path of the powershell cmdlet – in this case ExportTo-ExcelPDF. ps1. This file is included in the installation directory of SA by default.

The second argument of the MP command must be the full path to the directory in which EXCEL files have been put

 

awaiting print to PDF.

This powershell cmdlet will print out ALL EXCEL files of *.xls or .xlsx types to PDF files in the specified directory (or any subordinate directory).

Many other tasks could be accomplished by executing a powershell script in this way.