Something vaguely like this – at least to give you an idea of the logic. This might not be exactly what you need. I suggest getting "Learn PowerShell Toolmaking in a Month of Lunches" as it's designed to help you for exactly this kind of task. Note that this won't stop a "freeze and won't continue" situation – with WMI, there's no way to break the connection if the remote computer is holding it. It's a known weakness in WMI.