Most scripting languages have the ability to pause, in the case of
PowerShell look for a built-in cmdlet called Start-Sleep. However,
I ask myself, 'Do I really need to pause a script?' The
answer often comes back, 'Windows services have built-in controls to wait,
thus I rarely need the extra and explicit PowerShell Start-Sleep'.
Note 1: I am aware that we could simply use:
Restart-Service Spooler -force
Note 2: Observe how the timing parameter (-s) proceeds
its numeric value (10).
This example does highlight that
Start-Sleep may be a waste of time, and may make your script unnecessarily
complex. However, if we purely wanted to test Start-Sleep then this
example would illustrate the simplicity of the syntax.
Encouraging computers to sleep when not in use is a great idea -
until you are away from your desk and need a file on that remote sleeping machine!
Wake-On-LAN really will save you that long walk to awaken a hibernating
machine; however my reason for encouraging you to download this utility is
just because it's so much fun sending those 'Magic Packets'. As Wake-On-LAN (WOL) is free, see
if I am right, and you get a kick from arousing those sleeping machines.
WOL also has business uses for example, wakening machines so that they can have
their patches applied.
Note 5: You would need to have installed a module called
PSRemoteRegistry for this to work!
»
Summary of Windows PowerShell Start-Sleep
In terms of efficiency, the crucial question is do we need Start-Sleep at
all? Once you decide that you need to pause a script, then the syntax
is straightforward.
If you like this page then please share it with your friends
See more PowerShell examples of process and service
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems.
Fortunately, SolarWinds
have created the
Free WMI Monitor so that you can actually see and understand these gems of
performance information. Take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.