0

I'm creating a Windows VM in azure and want to execute a Powershell script to perform the following tasks:

  1. install SCCM client
  2. reboot, and SCCM task sequence will start in a few minutes.
  3. wait for the task sequence completes
  4. extra task 1
  5. extra task 2 ....

My problem is, during the waiting time in step 3, how to check if the task sequence is completed using Powershell and CIM class/WMI?

The apps being installed is a device collection and I don't login to the machine.

Digger
  • 55
  • 6

1 Answers1

0

If it is really necessary to do this way (normally your task could also be handled by sccm so no need to wait yourself, just make it an application or program and deploy it) the "Execution History" (where completion of SCCM programs and TS is logged) can be found in HKLM:\SOFTWARE\Microsoft\SMS\Mobile Client\Software Distribution\Execution History. There you can look for a key named after your TS PackageID, which will have a random subkey containing a REG_SZ _State which has success as entry once the TS is completed.

So for a Machine TS with ID SMS00001 you would need to check for something like

(Get-ChildItem -path "HKLM:\SOFTWARE\Microsoft\SMS\Mobile Client\Software Distribution\Execution History\System" -Recurse | where {$_.Name -like "*SMS00001*"} | foreach { get-itemproperty -path  $_.PsPath})._State
Syberdoor
  • 2,521
  • 1
  • 11
  • 14
  • Thank you. So if all package IDs under Execution History are marked succeed, can I say the TS is completed? – Digger Apr 22 '23 at 11:52
  • I’m making a GitHub workflow. In the workflow, I install sccm client and wait for its completion. After completed, I need to run the some commands which depend on the sccm installed packages, so I need detect if sccm TS is completed. – Digger Apr 22 '23 at 11:57
  • Generally speaking you can not say if everything you find is successful that it works, you would have to check for the specific ID of your TS. If this is not possible however I think in your special case you might be able to assume it that way because there is no client before the TS but I couldn't say for sure. However if your case is that special (and removed from the SCCM world) why not just make a final step in the TS that marks this as complete in a way that is useful/accessible for your workflow? It could even be possible to start your script and not wait for its completion as last step – Syberdoor Apr 24 '23 at 07:23