Author Posts

January 28, 2015 at 6:10 am

Hi admin,

Shouldnt it be possible to install a msi file on a remote servers through powershell?
When i run my "code" locally the installation works but when i put the code in a script block and using invoke-command nothing happens..

Any ideas?

Cheers
Johan

Invoke-Command -ComputerName $computer -ScriptBlock {
$msi = "c:\Notifier\Notifier-Windows-9.5.2-2022.i386.msi"
$arguments= ' /qn /l*v .\Notifier.log'
Start-Process -file $localmsifile -arg $arguments -passthru | wait-process}

January 28, 2015 at 6:14 am

Possible, yes. Straightforward, not necessarily. It depends entirely on what the MSI is trying to do – if it's raising any kind of interactive UI, or trying to access any non-local resources, it'll fail. A lot of MSIs also expect to have a user profile available to write to – e.g., directories, registry, etc. When you connect via Invoke-Command, you don't spin up a profile, and so that can cause the MSI to fail also. Not much workaround except rewriting the MSI itself to not have those requirements.

January 28, 2015 at 6:18 am

How does it fail? Does the MSI exist on the remote computer, or is that C:\ path referring to a file on the local machine?

January 28, 2015 at 6:23 am

Thanks for you super fast reply 🙂

I will then try do solve this in some other ways.

Cheers
Johan

January 28, 2015 at 6:28 am

Dave,

Yes the msi file exists on the server.
Below is what im trying to run:

$computername = Get-ADComputer -Filter 'name -like "kto-dmzapp-*"' |select -ExpandProperty name
$msifile = "\\kto-mgmt-01\d$\app\Notifier-Windows-9.5.2-2022.i386.msi"

foreach ($computer in $computername)
{
$destinationFolder = "\\$computer\C$\Notifier\"

if (!(Test-Path -path $destinationFolder))
{
New-Item $destinationFolder -Type Directory
}
Copy-Item -Path $msifile -Destination $destinationFolder

Invoke-Command -ComputerName $computer -ScriptBlock {
$localmsifile = "c:\Notifier\Notifier-Windows-9.5.2-2022.i386.msi"
$arguments= ' /qn /l*v .\Notifier.log'
Start-Process -file $localmsifile -arg $arguments -passthru | wait-process}

}

January 28, 2015 at 7:12 am

Looks like you're pretty much doing everything right. Anything in the Notifier.log file?

January 28, 2015 at 2:04 pm

Watch out for http://support.microsoft.com/kb/2918614. This broke our ability to install msi packages via posh remoting.

February 4, 2015 at 6:38 am

Hi, Thanks for your replies so far 🙂

I have now changed my "code" a little bit.
Now it works the way i want it except for one small issue... I have to be LOGGED IN on the servers!!!!

If im not logged in to the servers my script copies the msi file to the temp folder as it should and then tries to start the install but fails.
(10837 Error MsiInstaller Application 2015-02-04 15:10:38)

If im logged on to the remote servers when i run my scripts from the mgmt server it works as planned. (The same account which runs the script from the mgmt server)
All my servers are windows2012r2.

Maybe this isnt a powershell issue?
Advice?

Cheers
Johan

———–
$computers = Get-ADComputer -Filter 'name -like "kto-targ*"' | select -ExpandProperty name

foreach ($comp in $computers)
{
$destinationFolder = "\\$comp\d$\temp\"
#This section will copy the $sourcefile to the $destinationfolder. If the Folder does not exist it will create it.
if (!(Test-Path -path $destinationFolder))
{
New-Item $destinationFolder -Type Directory
}

$deploy = {
Set-Location "d:\temp"
& msiexec.exe /I Notifier-Windows-9.5.2-2022.i386.msi /quiet
}

Copy-Item -path \\kto-mgmt-01\d$\app\Notifier-Windows-9.5.2-2022.i386.msi -Destination \\$comp\d$\temp
$session = New-PSSession -ComputerName $comp
Invoke-Command -Session $session -ScriptBlock $deploy
}

February 4, 2015 at 6:46 am

This isn't a PowerShell [b]problem[/b], no. The MSI is attempting to write to the local profile; when you're not logged in on the server, there isn't a profile for it to write to, and so it fails. There's not much you can do about that except repackage the MSI to not need a local session. It's probably trying to write icons to a Start menu folder or something.

February 4, 2015 at 7:16 am

Thanks Don.

Makes sense,

Cheers
Johan