IT Process Automation

Expand all | Collapse all

Passing Parameters into Powershell Script

Jump to Best Answer
  • 1.  Passing Parameters into Powershell Script

    Posted 02-04-2016 10:44 AM

    I'm trying to pass a 'Process.' variable into PowerShell script using the parameters built into the Run Script operator but without an success.

    Below is what I currently have in the Inline Script box:

     

    param([string]$var1);

    Get-ChildItem -Path \\%%%source path%%% -Recurse | Where-Object {$_.Name -Like "*$var1"} | Move-Item -Destination \\%%%destination path%%%

     

    Is there a less verbose way to pass that variable into the Where-Object?

     

    I was reading the documentation here and liked the concept at the bottom of just using '%1' but haven't had any luck getting that to work.

    https://docops.ca.com/display/CATPA422/Run+Script+Operator

     

    I also found a post in the community but it didn't have an code samples

    ITPAM and PowerShell

     

    Any thougts or suggestions on how to streamline passing in variables?

     



  • 2.  Re: Passing Parameters into Powershell Script
    Best Answer

    Posted 02-05-2016 05:52 AM
      |   view attached

    I put in embedded PS inside like this:

    Param(
    [string] $var1
    )
    
    Get-ChildItem -Path C:\Temp -Recurse |Where-Object {$_.Name -like "*" + $var1 + "*"}
    

     

     

    to pass the variable, put in parameters in component like this sample attached. remember to mark thex check 'rear output for data set variable'

    Attachment(s)

    zip
    teste_2.xml.zip   5K 1 version


  • 3.  Re: Passing Parameters into Powershell Script

    Posted 05-30-2017 11:18 AM

    This seems to work but i cant seem to get multiple parameters to work... 

     

    For Instance:

    Param(
    [string] $var1, $var2
    )
    Get-Service -ComputerName "$var1" -Displayname "$var2" | Format-Table -Property status, displayname -AutoSize



  • 4.  Re: Passing Parameters into Powershell Script

    Posted 05-30-2017 03:07 PM

    Nevermind... figured it out. The issue really was the spaces being removed in the script. 

    I needed to wrap the parameters in the script operator parameter Properties panel. Like so...

     

    ("'") or double quote single quote double quote

     

     

    Then the actual script i was running: 

     

     

    Multiple params work and the spaces issue is resolved.