I'm trying to install an msi using remoting. It works without error when I run through each step in an interactive session using Enter-PSSesion, but fails when I try the same sequence using Invoke-Command. The general code is as follows
function Invoke-MsiInstall {
Param ($msiFile, $servers)
Scriptblock = {
Param ($msiFile)
$Args = "/i C:\windows\temp\$msiFile /qn"
Start-Process msiexec.exe $Args -wait
}
New-PsSession $Servers
Invoke-Command -Session (Get-PsSession) -Scriptblock $ScriptBlock -ArgumentList ($msiFile=$msiFile) -asJob
}
Invoke-MsiInstall -msiFile foo.msi -servers $serverlist
( the file foo.msi is copied to each server first )
I'm confounded as to why this works interactively using Enter-PsSession but doesn't work using Invoke-Command.
Any help is most appreciated!