/build/static/layout/Breadcrumb_cap_w.png
04/02/2019 302 views

Hi All


Been dealing with this script for awhile, and it works fine locally, but when I try to run it via SCCM and push it out to a handful of test machines, powershell.exe starts under System (as expected) but then just sits there.  Also the process it's supposed to close, doesn't get closed.  Everything deploys fine, it gets copied down to the ccmcache folder, and it runs, but then just sits there.  I don't think it's getting past the stop-process 'emsclient' part as it never kicks off the msi install, at least that I can tell.

I tried a standard silent install and that works ok, but then users have to reboot for the new software to work.  And our users are notoriously bad at doing that.


It's supposed to stop the currently running program that it's updating (emsclient)

Install the msi

Start the client back up.

Run gpupdate /force to get some info needed for the app to work.

Stop-Process -processname emsclient -Force
Start-Process msiexec.exe -Wait -ArgumentList '/i xinkClient.msi /qn REBOOT=ReallySuppress'
& 'C:\Program Files (x86)\Xink\Xink Client AD\emsclient.exe'
Invoke-command -Scriptblock { gpupdate /force }


I'm thinking that because it's running as system, that it doesn't see the emsclient.exe process, so not sure how to get it to see it, or if there is something else I'm missing.


Any help would be greatly appreciated.


0 Comments   [ + ] Show comments

Comments


All Answers

0

Try this.

Use psexec.exe from sysinternals to run as system and test (psexec -i -s powershell). Enter whoami to check you are SYSTEM.
Start-Process with msiexec.exe likes you have the full path to the msi, where as the Command Prompt you can get away without.

*[System.Environment]::Exit(0) you have to use a .net exit method or SCCM wont detect it.

#House keeping$ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition$MSI_Installer = 'xinkClient.msi'#Script workIf (Get-Process -Name emsclient -ErrorAction SilentlyContinue) {Stop-Process -ProcessName emsclient -Force}$MSI_Args = "/i $ScriptPath\$MSI_Installer REBOOT=ReallySuppress /qn /l*vx $Env:WinDir\Temp\xinkClient.msi.log"$Exitcode = (Start-Process msiexec.exe -ArgumentList "$MSI_Args" -Wait -PassThru).ExitCodeIf (($Exitcode -eq 0) -or ($Exitcode -eq 3010))    {If (Test-Path 'C:\Program Files (x86)\Xink\Xink Client AD\emsclient.exe') {'C:\Program Files (x86)\Xink\Xink Client AD\emsclient.exe'}     & gpupdate.exe /force      [System.Environment]::Exit(0)}Else{[System.Environment]::Exit(1)}

Argh, try here for powershell script.

https://pastebin.com/nGSqk9TT *Expires in one year.



Come to think of it, if you need to kill a process and have users control/give them a option with GUI, you might be better off using https://psappdeploytoolkit.com/

Recommend you check it out, as I suspect it will do everything you want it too and more. 

Answered 04/03/2019 by: rileyz
Red Belt

  • Thanks rileyz, it seemed to install ok, it got hung up when running gpupdate for some reason, but perhaps that was due to running it as system. Once I hit ctrl+c it finished the gpupdate, but it didn't launch the app prior to doing that. going to throw it in sccm and push it out to a test box and see how it goes. I'll keep you posted.
  • So it works from SCCM in that it kills the 'old' version, and installs the new, but for some reason it won't start it up from the 'test-path' line. Get that squared away and I'm golden.
  • I'm actually working this through PSADT also, and will be testing it today. Started working with that the other day. Mgmt wants it as 'silent' as possible.
    • Just realised you can't start the process, as it will running as system (which is bad, as users can gain elevated entry into the computer). Best to not start the process, and let the uses restart the process. Alternative is you don't kill the process, use PSADT and let that handle the reboot. I think sccm, if configured will reboot the system after 4 hours of a 3010 (reboot required).
      • Ah, that makes sense. I'll give PSADT a shot and see what happens.