This question is not answered
I have wrote a scripte, but my problem is that the $args not funktion in $script

$args1 = Read-Host "Path to MSI:"
#Debug Ausgabe args1
#Write-host $args1

$args2 = Read-Host "MSI Package:"
#Debug Ausgabe args2
#Write-host $args2

$args3 = Read-Host "Parameter for MSI:"
#Debug Ausgabe args2
#Write-host $args2

$args = "-i c:\Test\$args2 $args3"
#Debug Ausgabe args
#Write-Host $Args

$script = {

Write-Host "msiexec.exe $args"


$input | ForEach-Object {

Copy-Item $args1\$args2 -Destination \\$computername\c$\Test\ -Force
$computername = $_.Name
Invoke-Command -ComputerName $computername -ScriptBlock $script -ArgumentList $Args


All Replies
  • The ArgumentList parameter creates a PowerShell object that is an array of arguments, even if only one is provided. So, the $Args object passed to the script block isn't the same object as the $Args in the argument list. It's likely that msiexec can't parse it. Try this and see if it helps:

    $Script = {
        "msiexec.exe $($Args[0])"

  • $Args is a reserved variable used by Powershell, I would doubt you could use it at all. Just change the name of the variable and see if it works.
  • Good point. I just tried to set a value to $Args and not only did the value not set, but no error message was generated. Definitely change the name of your $Args variable OUTSIDE the script block.
  • I have change $args Variable to $tst outside the scriptblock, no error message was generated, but inside the scriptblock not set
  • thx for your help

    i found the solution

    first, i changed $var in $tst
    second, $script = {...} moved from outside to the invoke-Command

    Invoke-Command -ComputerName $computername -ScriptBlock {param($tst) [Diagnostics.Process]::Start("msiexec.exe",$tst).WaitForExit() } -ArgumentList $tst

    Now it is working:-)