Jeremy Jorgensen (Customer) asked a question.

Custom Script (Powershell) input variables/parameters like Command Line App

Is there a way to use a string like Command Line App's CommandLineApp_AppParms but for Custom Scripts (PS1)?

I am trying to use MOVEit Automation to kick off a process but I need to be able to define two variables in each Task and I can't figure out how to do it.

I added variables (eg jobname) and added $jobname in the script, but it's not accepting them (confirmed via a logfile write built into my script for testing)

When I try and add the script, it says:

imageBUT when I made the task, I added some variables:

imageWhat easily overlooked thing am I missing?


  • Richard Auger (https://pro2col.com/)

    Just use this in the powershell script:

    $foldername = $miaclient.MIGetTaskParam("foldername")

    $jobname = $miaclient.MIGetTaskParam("jobname")

     

    If you need to return a variable back into the task, use this:

    $miaclient.MISetTaskParam("jobname",$jobname)

     

    As an example, this PS script is used to accumulate filenames to pass into an email next action

     

     

    $append = $miaclient.MIGetTaskParam("Append")

    $newvalue = $miaclient.MIGetTaskParam("NewValue")

    $append = $append + $newvalue

    $a = $miaclient.MISetTaskParam("Append",$append)

    $a = $miaclient.MILogMsg($append)

     

    the parameter NewValue contains the [Origname] macro with some formatting, then I just use [PARM:Append] in the email

    Selected as Best
  • Chuck Fox (Customer)

    When I write PowerShell scripts for MOVEit, I always design them to be used as standalone scripts and add support for grabbing parameters from MOVEit. MOVEit provides a variable named $miaclient that allows you to easily interact with MOVEit from PowerShell. You can use the Test-Path commandlet to determine if you are inside MOVEit or running locally.

     

    Example:

     

    [CmdletBinding()]

    Param(

        [Parameter(Mandatory = $false)]

            [string]$Environment,

        [Parameter(Mandatory = $false)]

            [string]$Client,

        [Parameter(Mandatory = $false)]

            [string]$ManifestName,

        [Parameter(Mandatory = $false)]

            [string]$OutputType

    )

     

    if( Test-Path variable:\miaclient ){

        $Environment    = $miaclient.MIGetTaskParam("Environment")

        $Client         = $miaclient.MIGetTaskParam("Client")

        $ManifestName   = $miaclient.MIGetTaskParam("ManifestName")

        $OutputType     = $miaclient.MIGetTaskParam("OutputType")

    }

     

    function Write-Err {

        param( [string] $Msg )

        if( Test-Path variable:\miaclient ){

            $miaclient.MILogMsg( $Msg )

            $miaclient.MISetErrorCode(10000)

            $miaclient.MISetErrorDescription("Error: $Msg")

        }

        else {

            Write-Output "$(Get-Date -Format 'G' ) - ERROR - $Msg"

        }

        Add-Content -Value "$(Get-Date -Format 'G' ) - ERROR - $Msg" -Path $Global:LogFileName

        Write-EventLog -Logname Application -Source $Global:Source -EventID 102 -Message $Msg -EntryType Error

        Send-MailMessage -From $Global:From -To $Global:Recipients -Subject "Create-Manifest Error" -Body $Msg -SmtpServer "mta.server.us" -Priority "High"

    }

     

    Hope this helps,

     

    Chuck Fox

    Advisory Developer

    iPipeline, Inc.

  • Richard Auger (https://pro2col.com/)

    Just use this in the powershell script:

    $foldername = $miaclient.MIGetTaskParam("foldername")

    $jobname = $miaclient.MIGetTaskParam("jobname")

     

    If you need to return a variable back into the task, use this:

    $miaclient.MISetTaskParam("jobname",$jobname)

     

    As an example, this PS script is used to accumulate filenames to pass into an email next action

     

     

    $append = $miaclient.MIGetTaskParam("Append")

    $newvalue = $miaclient.MIGetTaskParam("NewValue")

    $append = $append + $newvalue

    $a = $miaclient.MISetTaskParam("Append",$append)

    $a = $miaclient.MILogMsg($append)

     

    the parameter NewValue contains the [Origname] macro with some formatting, then I just use [PARM:Append] in the email

    Selected as Best