I'm creating a Windows VM in azure and want to execute a Powershell script to perform the following tasks:
- install SCCM client
- reboot, and SCCM task sequence will start in a few minutes.
- wait for the task sequence completes
- extra task 1
- 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.
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_Statewhich 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