Powershell

How to start and stop services remotely using Powershell

How to start and stop services remotely using Powershell

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)

Final Thoughts

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.

Subscribe to VirtualizationHowto via Email ๐Ÿ””

Enter your email address to subscribe to this blog and receive notifications of new posts by email.



Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com, and a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.