Search code examples
powershellremote-accesswindows-serverwindows-installerinvoke-command

Remote install MSI package not working when logged off


I've got a problem with my script I'm working on. One part of this script should remotely install a MSI package. The problem is that it only works while I'm logged in to the target servers.

Here's the code I'm using:

1st try:

Invoke-Command -ComputerName $Computer -ScriptBlock {
    cd "C:\FlexAgent"
    Start-Process msiexec.exe -ArgumentList "/i 'FlexNet Inventory Agent.msi'  /qn /l newlogfile.txt"
}

2nd try:

Invoke-Command -ComputerName $Computer -ScriptBlock {
    cd "C:\FlexAgent"
    Invoke-Expression "msiexec /i 'FlexNet Inventory Agent.msi' /qn /l logfile.txt"
}

3rd try:

Invoke-Command -ComputerName $Computer -ScriptBlock {
    cd "C:\FlexAgent\"
    & msiexec /i 'FlexNet Inventory Agent.msi' /qn '/l*v' 'logfile.txt'
} 

Folder: FlexAgent:

    Directory: \\RemoteComputer\c$\FlexAgent


Mode                LastWriteTime     Length Name                                                                                                           
----                -------------     ------ ----                                                                                                           
d----        03.08.2018     09:47            ManageSoft upgrade agent                                                                                       
-a---        08.08.2017     12:34   15203756 Data1.cab                                                                                                      
-a---        08.08.2017     12:34    3089408 FlexNet Inventory Agent.msi                                                                                    
-a---        03.08.2018     11:26          2 logfile.txt                                                                                                    
-a---        29.05.2018     09:41       6985 mgssetup.ini                                                                                                   
-a---        08.08.2017     12:34    1308656 setup.exe                                                                                                      
-a---        08.08.2017     12:34       5350 Setup.ini 

I wasn't able to find any further information in the log files I defined or the logfiles in the event viewer. The logfiles are being created but they are empty.

Is there a way to install this MSI package unattended without the need to be logged in?


More Infos:

  • Target Servers: Windows Server 2008 - 2016
  • Script Server: Windows Server 2012 R2
  • Domain: Yes, they are all in the same domain.
  • User: Logged in with a Domain Admin
  • Network: All in the same network
  • Firewall:
    • TCP/5985 not blocked (used for remote PowerShell)
    • TCP/5986 not blocked (used for remote PowerShell)

Solution

  • I just found the solution. I was able to install the MSI package remotely with the following commands:

    $product= [WMICLASS]"\\$RemoteComputer\ROOT\CIMV2:win32_Product"
    $product.Install("C:\FlexAgent\FlexNet Inventory Agent.msi")
    

    It worked even when logged off.