I have the script below which is not working the way I want. Initially, I would like to pass install.cmd to function which will use the "Start-Job" in the background so that it doesn't freeze up the main Powershell window. But I can't get it to call the install.cmd.
$Appname = @("Adobe_FlashPlayer", "Acrobat_Reader", "Microsoft_RDP")
function BatchJob{
Param (
[ScriptBlock]$batchScript,
$ArgumentList = $null)
#Start the batch
$batch = Start-Job -ScriptBlock $batchScript -ArgumentList $ArgumentList
}
Foreach($App in $Appname){
$Install = "C:\test\$App\Install.cmd"
Batchjob -batchscript {Invoke-Command (cmd / c)} -ArgumentList $install
Wait-Job $job
Receive-Job $job
}
$Install = "C:\test\$App\Install.cmd"
but never reference it outside of that. I think you need yourInvoke-Command
to be{Invoke-Command "cmd.exe /c $install"}
You're going to run into issues though because (assuming more than one application uses the Windows Installer) the Windows Installer will be busy with the first application installation when you try to start the second (and third etc) and the applications past the first are going to fail.{Invoke-Command (cmd / c)}
has no defined parameters to which you would pass that argument. What exactly do you expect it to do with the argumentlist? Should it just intrinsically know to tack it on to the end of the command being passed toInvoke-Command
?