AddingTimeout to powershell script

Hello Experts,
I have a script which is getting hung and not able to proceed to next commandline
Below is the script
$ST = new-object -com schedule.service
$Server = "Server1"
$ST.Connect($server)
$M = $ST.GetFolder("\").GetTask("GWSTSAutoPatch")
It gets hung on $ST.GetFolder("\").GetTask("GWSTSAutoPatch") and wont proceed into next command.
Now , question is , Can I add a timeout on this? so , that script will wait for few sec and it will proceed if it does not get any response.
Thanks,
-Prashant Girennavar.

Featured Post

Managing Active Directory can get complicated. Often, the native tools for managing AD are just not up to the task. The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed.
Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…

The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…