3

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 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I had it copied locally originally but it wasn't working so I switched to UNC. Turns out the reason locally wasn't working was because msiexec didn't like a space in the file path for the .msi that was being passed in the "ArgumentList". Once I moved the .msi to a different path, and referenced the new path in my script, it worked perfectly. Thanks for your help, Remy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.