Hey everyone! I've set up a script that does several things for my Hyper-V VM: it reverts the VM to a base snapshot, scans for new patches, waits for some time, reboots the VM, and then takes a new snapshot. Right now, I make it wait for a whole hour to ensure all updates are applied before rebooting, but I want to optimize this. Is there a way to monitor CPU usage on the VM and only restart it once the CPU usage is consistently low (like around 0-1%) for about 5 seconds? I think this would guarantee that the patching is fully finished before I take a new snapshot. Any suggestions on how to implement this in my script?
3 Answers
Instead of just blindly waiting for CPU usage, you might want to directly check if the process you start for updating has finished. This way, you won't have to rely on CPU metrics alone. That could lead to a more reliable outcome.
You can definitely monitor CPU usage, but relying solely on 0-1% might not be the best way to determine if patching is complete. Have you thought about checking the process responsible for kicking off the patching instead? For example, if you're using ZENWorks, maybe monitor that process. Also, some tools like PSWindowsUpdate could handle the reboot for you after patching finishes. Just a thought!
What about checking for installed KBs? If a KB needs a restart, it should show as installed after patching. You could use that as a trigger for the restart instead of just timing out. That way, you wouldn't have to wait a full hour if the patches finish sooner.
True, but keeping track of all those KBs can be a pain. I'd rather let the script handle whatever patches come up automatically, then just snapshot the updated VM.

Yeah, ZAC is part of ZENWorks, right? It sets off the patch scan, which complicates things since it ends quickly. I see your point about monitoring that process—it might be a cleaner solution.