Hi,

I’m trying to install a .msi file which seems to be being hard work. Deploying it by broup policy and a startup script won’t work but I’ve found running it from powershell as administrator does work.

I tried to create a skip that will connect onto a list of PCs and run the install. The script starts but once the Enter-PSSession line runs, it just brings up the remote session and pauses, it doesn’t continue to run the rest of the script. If I manually enter the next lines it will run the install succesfully, delete the file and stop the service but it then doesn’t run through the loop.

$logfile = "C:\Scripts\Deploy.txt"
$cred = Get-Credential domain\Administrator
foreach($pc in (Get-content C:\Scripts\computers.txt)){
write-verbose "Working on $pc" -Verbose
  if(Test-Path "\\$pc\c$"){
        Get-Service -Name WinRM -ComputerName $pc | Set-Service -Status Running
        Copy-Item "\\Server\FileShare\file.msi" \\$pc\c$\WINDOWS\Temp\
        Enter-PSSession –ComputerName $pc –Credential $cred
        msiexec.exe /i "C:\WINDOWS\Temp\file.msi" /qn /log "C:\Windows\Temp\InstallLog.txt"
        exit
        Remove-Item "\\$pc\c$\WINDOWS\Temp\file.msi"
        Get-Service -Name WinRM -ComputerName $pc | Set-Service -Status Stopped
  }else{Add-content $Logfile -value $pc}
}

Does anyone have any pointers?

3 Spice ups

What you describe seems to be “expected” due to the way enter-pssession works.

What if you replace “enter-pssession” with “invoke-command”? That should do what you want.

1 Spice up

Is it getting stuck on waiting for Execution policy override?

If you post code, please use the ‘Insert Code’ button. Please and thank you!

codebutton_small.png

that is expected behavior. As Carl mentioned, ‘enter-pssession’ is interactive.

If you want to automate that, you have to use ‘invoke-command’

Why you turn winRM explicitly on and then off, is beyond me…

e.g.

$logfile = "C:\Scripts\Deploy.txt"
$cred = Get-Credential domain\Administrator
$list = Get-content "C:\Scripts\computers.txt"

foreach ($pc in $list) {
    write-verbose "Working on $pc" -Verbose
    if (Test-Path "\\$pc\c$") {
        Get-Service -Name WinRM -ComputerName $pc | Set-Service -Status Running
        Copy-Item "\\Server\FileShare\file.msi" \\$pc\c$\WINDOWS\Temp\
        invoke-command –ComputerName $pc –Credential $cred -ScriptBlock {
            msiexec.exe /i "C:\WINDOWS\Temp\file.msi" /qn /log "C:\Windows\Temp\InstallLog.txt"
        }
        Remove-Item "\\$pc\c$\WINDOWS\Temp\file.msi"
        Get-Service -Name WinRM -ComputerName $pc | Set-Service -Status Stopped
    }
    else { 
        Add-content $Logfile -value $pc
    }
}
1 Spice up

If I use invoke command as such:

Invoke-Command -ComputerName $pc -Credential $cred -ScriptBlock { msiexec.exe /i "c:\WINDOWS\Temp\file.msi" /qn /log "C:\Windows\Temp\InstallLog.txt" }

Then the software doesn’t install, it comes back with a 1603 error in the log. It seems to stop at “MigrateFeatureStates. Return value 0.”

that really depends on the MSI / installer.

The link at sync.com seems to be suggesting to allow install by users rather than just administrators, but I’m giving it the domain admin credential?

that is one of the many things error 1603 could mean, but the real meaning depends on the installer file.