3
votes

I am trying to get an application to install on a remote server using powershell. Here is the script I am using:

$cred = Get-Credential
$s = New-PSSession -ComputerName $ServerName -Credential $cred

Invoke-Command -Session $s -ScriptBlock {Start-Process -FilePath "c:\windows\system32\msiexec.exe" -ArgumentList "/i \\computer\e$\installer.msi /qn" -Wait}

Remove-PSSession -ComputerName $ServerName

If I run the following on the remote computer directly, it executes beautifully:

Start-Process -FilePath "c:\windows\system32\msiexec.exe" -ArgumentList "/i \\computer\e$\installer.msi /qn" -Wait

But when I run it remotely as a part of the Invoke-Command, the PS Session is opened, the script runs, msiexec starts on the remote computer, then the PS Session closes but the application never installs and msiexec never closes.

Any help would be appreciated.

Thanks,

Zach

1

1 Answers

4
votes

You'll need to copy the package locally first. Once you start remoting you can no longer UNC.

The destination can be anywhere on the server/computer. I use the temp but it's whatever you like.
Also I like to use $env:windir\temp, just in case.

    Copy-item "\\servershare\File.msi" -conatiner -recurse `
               \\$Computer\c$\windows\temp\

    Invoke-Command -Computername $Computer -credential $cred -ScriptBlock {
        Start-Process -FilePath `
        "c:\windows\system32\msiexec.exe" `
        -ArgumentList "/i `
        \\computer\e$\installer.msi /qn" -Wait
        }

I hope it helps.