locked
Using a variable for a whole command line RRS feed

  • Question

  • Hi,

    Is it possible to put that commandline:

    Execute-MSI -Action Install -Path "$Var_SourceFiles\$($Itemvar_Setup_Parameter[0])" -transform $Itemvar_Setup_Parameter[1] `
    												-Parameters $Itemvar_Setup_Parameter[2]`
    												-LogName "$var_PackageLongName"

    in a single variable and then just run the variable instead of writing the whole command line?

    Thanks,

    Sunday, January 25, 2015 4:06 AM

Answers

  • You can put in a script file and call the script.

    .\myscript.ps1

    You canput it in a variable like this:

    $sb=[scriptblock]::Create('Execute-MSI -Action Install -Path $Var_SourceFiles\$Itemvar_Setup_Parameter[0] -transform $Itemvar_Setup_Parameter[1] -Parameters $Itemvar_Setup_Parameter[2] -LogName $var_PackageLongName')
    $sb.Invoke()

    You cannot pu tit in a variable and run it except.

    Your command also leaves a lot to be desired in a PowerShell session.


    ¯\_(ツ)_/¯

    • Marked as answer by AnnaWY Friday, February 6, 2015 7:26 AM
    Sunday, January 25, 2015 4:31 AM

All replies

  • You can put in a script file and call the script.

    .\myscript.ps1

    You canput it in a variable like this:

    $sb=[scriptblock]::Create('Execute-MSI -Action Install -Path $Var_SourceFiles\$Itemvar_Setup_Parameter[0] -transform $Itemvar_Setup_Parameter[1] -Parameters $Itemvar_Setup_Parameter[2] -LogName $var_PackageLongName')
    $sb.Invoke()

    You cannot pu tit in a variable and run it except.

    Your command also leaves a lot to be desired in a PowerShell session.


    ¯\_(ツ)_/¯

    • Marked as answer by AnnaWY Friday, February 6, 2015 7:26 AM
    Sunday, January 25, 2015 4:31 AM
  • See: PS> get-help invoke-expression -detail

    This may accomplish what you are trying to do.

    Sunday, January 25, 2015 7:53 PM
  • Sounds interesting.
    Sunday, January 25, 2015 11:21 PM