Powershell is one of the coolest new things that has happened to Windows in recent iterations. It provides a wealth of scripting power to administrators and even to home users who may want to do some things quickly and efficiently with their workstations. One thing is for sure Microsoft is building all of their new technologies and software with Powershell capabilities deeply embedded and have made it clear that this is the scripting engine they are moving forward with.
Powershell does so many things more easily than other scripting languages and takes only a single line of code now to do things that may have taken many lines of VB script or batch scripting to accomplish. It’s modular design as well makes it very powerful in that 3rd party applications can write modules that integrate into the core Powershell framework to enhance or give you control over other software packages utilizing Powershell.
We will be doing more posts here on common tasks that you can use Powershell to accomplish and one of those that we want to begin the series with is stopping and starting a service. Have you ever tried to connect to a workstation either remotely or with a software tool that depended on a service being running on that workstation only to realize the service is not running on the remote workstation? In steps Powershell.
Start a service remotely
Use the start-service powershell commandlet to start a service remotely:
start-service -inputobject $(get-service -ComputerName remotePC -Name Spooler)
Stop a service remotely
Alternately, you may need to stop a service using the stop-service command
stop-service -inputobject $(get-service -ComputerName remotePC -Name Spooler)
Restarting a service
To combine the above commands if you want to stop AND start a service (restart) you can utilize the restart-service commandlet:
restart-service -inputobject $(get-service -ComputerName remotePC -Name Spooler)
The above commandlets are a great way to easily take care of administrative tasks that might otherwise take a lot of time or leg work (literally) to accomplish. We will continue the powershell series with other common tasks that can easily be done using powershell.