Wednesday, September 21, 2016

Managing a Windows Service using PS


Administrators can control all Windows Services in their domain using PowerShell.

Get-Service is the most common cmdlet.

The basic Get-Service with no parameters shows all services on the local computer.

But most administrators will need to find services on remote computers. This can be done with the ComputerName parameter

Get-Service -ComputerName Sathees-PC

Multiple Computers

What if you want to see the services on multiple computers? Powershell has a cmdlet Get-Content that can read a text file which has computers names and by using a foreach loop, we can run Get-Service for each of those computers names.

Get-Content C:Script\Computers.txt | foreach {Get-Service -ComputerName $_}

Changing a Computer's Service with PS

Let's get a little deeper and change some of the services. For example, let's start the Application Layer Gateway service on all computers in that text file. By specifying a particular service to find and then piping that object to Restart-Service.

Get-Content C:Script\Computers.txt | foreach {Get-Service -ComputerName $_ -Name ALG | Restart Service}

Hope, You will not get any Red text from PS output.

The output can be viewed using below command.

Get-Content C:Script\Computers.txt | foreach {Get-Service -ComputerName $_ -Name ALG}

Ref link: here

No comments:

Post a Comment