Script Block powershell remote MSI Installation

14,169

Since you created a PSSession, use the -ComputerName parameter on New-PSSession.

Parameter Set: ComputerName
New-PSSession [[-ComputerName] <String[]> ] [-ApplicationName <String> ] [-Authentication <AuthenticationMechanism> ] [-CertificateThumbprint <String> ] [-ConfigurationName <String> ] [-Credential <PSCredential> ] [-EnableNetworkAccess] [-Name <String[]> ] [-Port <Int32> ] [-SessionOption <PSSessionOption> ] [-ThrottleLimit <Int32> ] [-UseSSL] [ <CommonParameters>]

Move the-Session parameter on Invoke-Command outside the scriptblock:

Invoke-Command -Session $session -ScriptBlock `
    {Start-Process "msiexec.exe" -ArgumentList "/i C:\DailyBuild\DirectMSI.msi INSTALLLOCATION=D:\Websites\DirectDevInt ENVPROPERTY=DEV /qb" -Wait}

Then remove -ComputerName paremeter on Invoke-Command since you are using the Session paremeter set.

Parameter Set: Session
Invoke-Command [[-Session] <PSSession[]> ] [-ScriptBlock] <ScriptBlock> [-ArgumentList <Object[]> ] [-AsJob] [-HideComputerName] [-InputObject <PSObject> ] [-JobName <String> ] [-ThrottleLimit <Int32> ] [ <CommonParameters>]
Share:
14,169
Chat
Author by

Chat

Updated on June 04, 2022

Comments

  • Chat
    Chat almost 2 years

    Hi I was trying to execute MSI from build machine A(cttfs) and install that MSI on Machine B(c2devint); output is website on Machine B.

    Please help me fixing the powershell script which is on Machine A with MSI installer.This script is run from Machine A

    $cred = Get-Credential username
    $session = new-PSSession -name c2devint -credential $cred
    Invoke-Command -ScriptBlock {Invoke-Command -Session $session -ScriptBlock {Start-Process "msiexec.exe" -ArgumentList "/i C:\DailyBuild\DirectMSI.msi INSTALLLOCATION=D:\Websites\DirectDevInt ENVPROPERTY=DEV /qb" -Wait} -ComputerName c2devint}
    Remove-PSSession $session
    

    Here is the error

     Invoke-Command : Parameter set cannot be resolved using the specified named parameters.
        At line:3 char:44
        + Invoke-Command -ScriptBlock {Invoke-Command <<<<  -Session $session -ScriptBlock {Start-Process "msiexec.exe" -ArgumentList "/i C:\DailyBuild\DirectMSI.msi INSTALLLOCATION=D:\Websites\DirectDevInt ENVPROPERTY=DEV /qb" -Wait} -ComputerName c2devint}
            + CategoryInfo          : InvalidArgument: (:) [Invoke-Command], ParameterBindingException
            + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand
    

    And also please help me how to pass username & pwd to this script

  • Chat
    Chat almost 11 years
    Hi Andy i think you have given below one as your answer; but this installs MSI which is on Machine A onto Machine A rather than Machine B. I want install MSI on remote machine B. "Invoke-Command -Session $session -ScriptBlock ` {Start-Process "msiexec.exe" -ArgumentList "/i C:\DailyBuild\DirectMSI.msi INSTALLLOCATION=D:\Websites\DirectDevInt ENVPROPERTY=DEV /qb" -Wait}"
  • Andy Arismendi
    Andy Arismendi almost 11 years
    @Chatrapathi no, it should run msiexec remotely on machine B.
  • Chat
    Chat almost 11 years
    But in this statement we don't have specified any -computername and its credentials. Can you please give me the statement with it."Invoke-Command -Session $session -ScriptBlock ` {Start-Process "msiexec.exe" -ArgumentList "/i C:\DailyBuild\DirectMSI.msi INSTALLLOCATION=D:\Websites\DirectDevInt ENVPROPERTY=DEV /qb" -Wait}"
  • Chat
    Chat almost 11 years
    I think this is statement you are asking me to run. I ran below stmt;and it was running for ever not doing anything. After I ran it just asked my pwd of the username.Can I give pwd in the statement ;if so how can i provide it in the statement. /***************/ $cred = Get-Credential c2\chennamc $session = new-PSSession -ComputerName c2devint -credential $cred Invoke-Command -Session $session -ScriptBlock {Start-Process "msiexec.exe" -ArgumentList "/I C:\DailyBuild\DirectMSI.msi INSTALLLOCATION=D:\Websites\DirectDevInt ENVPROPERTY=DEV /qb" -Wait} Remove-PSSession $session
  • Andy Arismendi
    Andy Arismendi almost 11 years
    @Chatrapathi read the section Establish a Persistent Connection
  • Chat
    Chat almost 11 years
    Hi Andy for some reason the ps1 script on MachineA is installing MSI on Machine A itself and creating out put of MSI at INSTALLLOCATION=D:\Websites\DirectDevInt on Machine A instead of Machine B.