Forum Discussion

webmasterSANTEE's avatar
webmasterSANTEE
Copper Contributor
Sep 12, 2024

[resolved] Variables are not consistent

Hello internet.

 

My mind is completely blown by this!

 

I have a PowerAutomate that sets some 'compose' actions and then uses them to start a job.  It is a PowerShell 7.2 script running in a Runbook extension-based hybrid worker on a Debian 11 Azure VM.

 

I've reduced the script to just printing the inputted variable values.  That's all, yet it provides them transposed!

 

 

 

 

 

 

param
(
    [string] $siteNAME,
    [string] $OMd,
    [string] $userNAME,
    [string] $templateNAME
)
$scriptVERSION = "x.y.z"
function WO { write-output $wriOU }
write-output "----------------------------------"
$wriOU = "siteNAME: "+$($siteNAME);WO
$wriOU = "OMd: "+$($OMd);WO
$wriOU = "userNAME: "+$($userNAME);WO
$wriOU = "templateNAME: "+$($templateNAME);WO
write-output "----------------------------------"
$wriOU = "Script Version: [ "+$scriptVERSION+" ]";WO
write-output "-end of line-"
#EOF

 

 

 

 

 

 

 

 

As you can see 'siteNAME' retains the value correctly.  But then 'OMd', 'username', and 'templateNAME' goes sideways so hard...  Why?  What am I doing wrong, this seems super odd...

 

Any insight is greaaaatly appreciated.

 

TY!

  • webmasterSANTEE 

     

    This is expected when named parameters aren't explicitly specified in a call to a PowerShell script, function or commandlet. In such a scenario, any supplied parameter values are mapped to parameter declarations in the order passed.

     

    Using your script definition, this would be the correct way to call it using named parameters:

     

    Invoke-MyScript -siteName "siteValue" -OMd "omdValue" -userNAME "usernameValue" -templateNAME "tempnameValue";

     

    But you are likely calling it like this - which is supported by the matching order of your input variables and subsequent output:

     

    Invoke-MyScript "siteValue" "usernameValue" "tempnameValue" "omdValue";

     

    Either re-order your input variables or use name parameters to resolve the issue.

     

    Cheers,

    Lain

  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    webmasterSANTEE 

     

    This is expected when named parameters aren't explicitly specified in a call to a PowerShell script, function or commandlet. In such a scenario, any supplied parameter values are mapped to parameter declarations in the order passed.

     

    Using your script definition, this would be the correct way to call it using named parameters:

     

    Invoke-MyScript -siteName "siteValue" -OMd "omdValue" -userNAME "usernameValue" -templateNAME "tempnameValue";

     

    But you are likely calling it like this - which is supported by the matching order of your input variables and subsequent output:

     

    Invoke-MyScript "siteValue" "usernameValue" "tempnameValue" "omdValue";

     

    Either re-order your input variables or use name parameters to resolve the issue.

     

    Cheers,

    Lain

    • webmasterSANTEE's avatar
      webmasterSANTEE
      Copper Contributor
      My hero!
      Alas, I can't change the order the PowerAutomates Create Job presents the fields. But I can change the order in the powershell script to match how PA presents and it worked like a champ.
      Thank you so much for getting me back on path!
      ~Santee

Resources