none
MSI Remote Installation Question!

    Question

  • Trying to install a basic MSI package (first Attempt), i have a script (well, more of a on line) which suppose to work and it looks ok to me as well. Network part and PC firewall is ok, remoting is enabled. anyway could you have a little peek at it and let me know if i am doing something wrong?

    (Get-WMIObject -ComputerName MypC -credential Administrator -List | Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).Install("C:\Windows\System32\flash.msi")
    

    Following is the Error Message:

    Get-WmiObject : Could not get objects from namespace root\cimv2. The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
    At line:1 char:15
    + (Get-WMIObject <<<< -ComputerName MypC -credential Administrator -List | Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).Install("C:\Windows\System32\flash.msi")
      + CategoryInfo     : ObjectNotFound: (:) [Get-WmiObject], COMException
      + FullyQualifiedErrorId : INVALID_NAMESPACE_IDENTIFIER,Microsoft.PowerShell.Commands.GetWmiObjectCommand
    You cannot call a method on a null-valued expression.
    At line:1 char:140
    + (Get-WMIObject -ComputerName MypC -credential Administrator -List | Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).Install <<<< ("C:\Windows\System32\flash.msi")
      + CategoryInfo     : InvalidOperation: (Install:String) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull
    Any Thoughts??

    Thursday, November 18, 2010 7:26 PM

Answers

  • Hi,

    The best way to do a remote msi installation is as follows:

    1. Set the access to the remote location if the MSI is stored at a remote location
    C:\Windows\System32\net.exe use $RemotePath password /user:username

    2. Copy the MSI file to the system you want to install it to.

    Create the C:\Temp folder if it doesnot exist
    if(!(Test-Path "C:\Temp"))
        {
            New-Item -Path "C:\Temp" -ItemType directory
        }
    Copy-Item "$RemotePath" "C:\Temp"

    3. Use the WIN32_Product Class in the following way
    $product= [WMICLASS]"\\.\ROOT\CIMV2:win32_Product"

    4. Now use the install method which otherwise is not shown up when we just use Get-WMIObject cmdlet
    $ret = $product.Install("C:\Temp\MyProduct.msi","ADDLOCAL=ALL",$true)

    5. If you want you can delete the msi file which you copied to the C:\Temp folder.


    I dont know exactly why the Install method doesn't work as the way it should when we use the Get-WMIObject cmdlet.

    This is the way i do the installations and it works fine for me. It works fine even if the msi installer is on a remote location or on the same machine. By the way you can skip step 1&2 if the installer is on the same machine.

    Few other things you would need to ensure that the installation works is that

    1. If the machines are less than windows 2008 then make sure that you install the WMI Installer Provider windows component.
    If you see any error saying generic failure then do the following
    Install Windows Installer 4.5
    http://www.microsoft.com/downloads/en/details.aspx?FamilyID=5a58b56f-60b6-4412-95b9-54d056d6f9f4&displaylang=en

    Install Hotfix for Windows Installer 4.5
    http://support.microsoft.com/kb/970553
    After a reboot this should work.

    2. Please ensure that the user credentials you will be using to do these tasks should have admin rights.

    Please do let me know if this works for you.

    Regards

    Sachin

    • Marked as answer by iM3th0 Sunday, November 21, 2010 1:30 PM
    Friday, November 19, 2010 7:13 AM
  • Hi iM3th0,

    Try this

    [ScriptBlock] $script = {

        $ErrorActionPreference = "Stop"
        $product= [WMICLASS]"\\.\ROOT\CIMV2:win32_Product"
        $ret = $product.Install("C:\Temp\MyProduct.msi","ADDLOCAL=ALL",$true)
        if ($ret.returnvalue -ne 0)
        {
            throw "Install failed for MyProduct.msi. Error Code: $($ret.returnvalue)"
        } 

    }
    $cred = Get-Credential
    $session = New-PSSession -ComputerName "MyPC" -Credential $cred
    Invoke-Command -ScriptBlock $script -Session $session
    $session | Remove-PSSession

    This should work. If there is any error during the installation process we will get it on the output so as to identify what went wrong. Looking at the error code and the eventlog on the machine we will be able to find out if the script actually worked. Any errorcode other than 0 means a failed installation. so lets see.

    Please do let me know if it worked for you.

    Regards

    Sachin

    • Marked as answer by iM3th0 Sunday, November 21, 2010 1:30 PM
    Saturday, November 20, 2010 6:49 PM

All replies

  • The reference to "RPC server is unavailable" usually refers to a problem with the network connection possibly because of a firewall.  Are you able to do any other simple get-wmiobject calls against this remote computer?
    Friday, November 19, 2010 1:22 AM
    Moderator
  • This should be another way to do it once you have your permissions sorted.

    Check the $domain $host and $options.

    $rem = Get-WMIObject -ComputerName $hostname -List Win32_Product -Authority kerberos:$domain\$host -Impersonation Delegate
    $rem.install("install.msi",$options,$true)

     

    Check here for Win32_Product Install Method http://msdn.microsoft.com/en-us/library/aa390890%28v=VS.85%29.aspx


    Hope this helps. Also you should check your RPC ports 135 445 make sure you have no f/w blocking the RPC connections.


    Sean Wright Blog: http://scriptastic.wordpress.com
    Friday, November 19, 2010 1:39 AM
  • Hi,

    The best way to do a remote msi installation is as follows:

    1. Set the access to the remote location if the MSI is stored at a remote location
    C:\Windows\System32\net.exe use $RemotePath password /user:username

    2. Copy the MSI file to the system you want to install it to.

    Create the C:\Temp folder if it doesnot exist
    if(!(Test-Path "C:\Temp"))
        {
            New-Item -Path "C:\Temp" -ItemType directory
        }
    Copy-Item "$RemotePath" "C:\Temp"

    3. Use the WIN32_Product Class in the following way
    $product= [WMICLASS]"\\.\ROOT\CIMV2:win32_Product"

    4. Now use the install method which otherwise is not shown up when we just use Get-WMIObject cmdlet
    $ret = $product.Install("C:\Temp\MyProduct.msi","ADDLOCAL=ALL",$true)

    5. If you want you can delete the msi file which you copied to the C:\Temp folder.


    I dont know exactly why the Install method doesn't work as the way it should when we use the Get-WMIObject cmdlet.

    This is the way i do the installations and it works fine for me. It works fine even if the msi installer is on a remote location or on the same machine. By the way you can skip step 1&2 if the installer is on the same machine.

    Few other things you would need to ensure that the installation works is that

    1. If the machines are less than windows 2008 then make sure that you install the WMI Installer Provider windows component.
    If you see any error saying generic failure then do the following
    Install Windows Installer 4.5
    http://www.microsoft.com/downloads/en/details.aspx?FamilyID=5a58b56f-60b6-4412-95b9-54d056d6f9f4&displaylang=en

    Install Hotfix for Windows Installer 4.5
    http://support.microsoft.com/kb/970553
    After a reboot this should work.

    2. Please ensure that the user credentials you will be using to do these tasks should have admin rights.

    Please do let me know if this works for you.

    Regards

    Sachin

    • Marked as answer by iM3th0 Sunday, November 21, 2010 1:30 PM
    Friday, November 19, 2010 7:13 AM
  • First of all, thanks for replying! 

    Marco, you was right about the firewall exception! i had to enable a RemoteAdmin with the following command

    Netsh firewall set service RemoteAdmin

    this command allowed me to manipulate wmiobjects and almost got my one liner working. problem is that, it works and i can see msiexec running on remote machine after that nothing happens (like i said almost). any thoughts

     

    PS C:\Windows\system32> (Get-WMIObject -ComputerName mypc -credential Administrator -List | Where-Object -FilterScript {$_.Name -eq "Win32_Product"}).Install("msiexec /i","C:\Windows\System32\flash.msi")
    

     

    SchinNair, 

     

    WOW dude, whata response, quite an eye opener, you tip about windows Installer along with RemoteAdmin did the job. although i still cant see on XP what i have opened with above command, lol, but it works! you said if the file is already there on remote PC than i should just use 3 and 4, thats what i did, i created a script with those two lines as it is, and used the following method to execute on the remote PC, it did nothing!

    Invoke-Command -ComputerName mypc -FilePath C:\Scripts\test.ps1 -Credential Administrator

    test.ps1 is the script with you two lines mentioned in you post, could you please let me know if i am doing something wrong? i am using the right method to execute the script on my workgroup XP from Workgroup win7? 

    (Script)

    $product= [WMICLASS]"\\.\ROOT\CIMV2:win32_Product"
    $ret = $product.Install("C:\Temp\MyProduct.msi","ADDLOCAL=ALL",$true)
    

    Guys, i am almost there, just need a bit of a push!
    Cheers

     


    Friday, November 19, 2010 3:25 PM
  • Hi iM3th0,

    Try this

    [ScriptBlock] $script = {

        $ErrorActionPreference = "Stop"
        $product= [WMICLASS]"\\.\ROOT\CIMV2:win32_Product"
        $ret = $product.Install("C:\Temp\MyProduct.msi","ADDLOCAL=ALL",$true)
        if ($ret.returnvalue -ne 0)
        {
            throw "Install failed for MyProduct.msi. Error Code: $($ret.returnvalue)"
        } 

    }
    $cred = Get-Credential
    $session = New-PSSession -ComputerName "MyPC" -Credential $cred
    Invoke-Command -ScriptBlock $script -Session $session
    $session | Remove-PSSession

    This should work. If there is any error during the installation process we will get it on the output so as to identify what went wrong. Looking at the error code and the eventlog on the machine we will be able to find out if the script actually worked. Any errorcode other than 0 means a failed installation. so lets see.

    Please do let me know if it worked for you.

    Regards

    Sachin

    • Marked as answer by iM3th0 Sunday, November 21, 2010 1:30 PM
    Saturday, November 20, 2010 6:49 PM
  • Thanks Sachin, you dont know how much i appreciate that... thanks again!!!

    one more thing, if i were to use that script to target more than one pc, would i be adding get-content cmdlet ? if yes, how would that work with sessions?

     

    $cred = Get-Credential
    $session = New-PSSession -ComputerName (get-content c:\complist.txt) -Credential $cred
    Invoke-Command -ScriptBlock $script -Session $session
    $session | Remove-PSSession

     

    is that possible? 

    thanks again!

    Sunday, November 21, 2010 1:46 PM
  • Hi iM3th0,
    The script should work for more than one target pc. Actually you can use this as a template to do almost anything in powershell remoting. This is the template i use generally. It works 99% of the times :).
    Just remember that steps 1 & 2 in my 1st post are important if you intend to do the remote installation on many machines.
    $machines = Get-Content "C:\MachineList.txt"
    [ScriptBlock] $script = {
    #Do something
    }

    $cred = Get-Credential
    $sessions = $machines | New-PSSession -Credential $cred
    Invoke-Command -ScriptBlock $script -Session $sessions
    $sessions | Remove-PSSession


    Regards

    Sachin

    Sunday, November 21, 2010 5:33 PM
  • Hi Sachin,

    i really like your way of scripting, the only difference my script is different from yours is i am passing parameters

    $cmdlineArgs = "ALLUSERS=1 REBOOT=ReallySuppress INSTALLDIR=c:\data\ SERVICEACCOUNT=$env:userdomain\$svcAcctName SERVICEPASSWORD=$svcAcctPwd "

     

     

    [ScriptBlock] $script = {

     

        $ErrorActionPreference = "Stop"

        $product= [WMICLASS]"\\.\ROOT\CIMV2:win32_Product"

        $ret = $product.Install($srcPath,$cmdlineArgs,$true)

        if ($ret.returnvalue -ne 0)

        {

            throw "Install failed for MyProduct.msi. Error Code: $($ret.returnvalue)"

        } 

     

    }

     

     

    I am getting the below error:-

    Exception calling "Install" : "Invalid method Parameter(s) "

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : WMIMethodException

     

     

    can you please help me in this regard


    Ismail Ahmed Syed | Senior Application Architect\Developer Small things make perfection but perfection is not a small thing
    Saturday, November 27, 2010 7:36 AM
  • Hi Ismail,

    I guess there is something wrong you are passing in the parameters. Thats the reason you are getting these errors. My bet is on the INSTALLDIR property, since its a path and i guess it may need quotes. Not sure though.

    Here is what you can try for troubleshooting

    1. Enable logging for windows installer

    http://support.microsoft.com/kb/223300

    2. Manually install the msi once and provide all the necessary parameters. After a sucessful installation check the temp folder where the msi logs are saved(mentioned in above link). In the logs you will be able to find the appropriate parameters and their exact names. This you can use to rectify your $cmdlineArgs.

    3. Download orca

    http://www.technipages.com/download-orca-msi-editor.html

    This is an msi editor tool this will also help in identifying parameters that can be supplied during installation.

    I am assuming that yours is an operating system above windows 2008 . If not you will have to do the things mentioned in the earlier post regarding the windows installer hotfix and stuff.

    I hope this hepls

    Regards

    Sachin

    Saturday, November 27, 2010 10:48 AM
  • Hi 

    I already to run your script but have issue..


    Hi I can't to find solution for solve this issue, I have Event 364 Source File: /Content/1B/DCD02B975BCC454188A2BB1F036E3E590C25641B.exe Destination File: D:\WSUS\WsusContent\1B\DCD02B975BCC454188A2BB1F036E3E590C25641B.exe But I don't know how to deline this KB Number..

    Friday, June 16, 2017 6:51 AM
  • Hi 

    I already to run your script but have issue..


    Hi I can't to find solution for solve this issue, I have Event 364 Source File: /Content/1B/DCD02B975BCC454188A2BB1F036E3E590C25641B.exe Destination File: D:\WSUS\WsusContent\1B\DCD02B975BCC454188A2BB1F036E3E590C25641B.exe But I don't know how to deline this KB Number..

    You are posting on a 7 year old thread that has been closed and answered. Also it is useless to post pictures of code and errors as they cannot be copied and the errors are hard to read.

    If you have a script that you have written and a question please open your own question with the information and someone will try to help you.

    To get error messages we would do the following:

    PS D:\scripts> net helpmsg 3
    
    The system cannot find the path specified.
    
    Open your own question if you still have issues.


    \_(ツ)_/


    Friday, June 16, 2017 7:09 AM
    Moderator