Solved

Schedule Restart of a specific windows service (Application Specific) PowerShell

Posted on 2016-07-25
6
35 Views
Last Modified: 2016-08-22
Hello all,

I want to stop a specific windows service using powershell and if it fails to stop, want to force stop using the script.
All I want to do is to schedule the script which will stop the service and force stop if it does not stop.

Even in case the service will not stop is there any possibility to check or get a notification that it has not stopped.
In one of the maintenance we are suppose to login to 100 servers to stop one service and run a script to start the application maintenance which is taking a long time. Any idea will be appreciated and of great help

Urgent :(
0
Comment
Question by:PavanPA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:Benjamin Voglar
ID: 41728862
$ServiceName = "WinRM"


$arrService = Get-Service -Name $ServiceName



if ($arrService.Status -eq "Running"){
stop-Service $ServiceName -Force }

Open in new window

0
 
LVL 12

Accepted Solution

by:
Benjamin Voglar earned 500 total points (awarded by participants)
ID: 41728877
This script will stop service "Winrm" on all computers in file servesrs.txt


$comp = Get-Content -Path 'C:\it\servers.txt'
 


ForEach  ($obj in $comp) {


Invoke-Command -ComputerName $obj -ScriptBlock{


$ServiceName = "WinRM"


$arrService = Get-Service -Name $ServiceName 



if ($arrService.Status -eq "Running"){
stop-Service $ServiceName -Force }

}

}
    

Open in new window

0
 

Author Comment

by:PavanPA
ID: 41729272
I will try this on one of the development server and confirm by tomorrow.... :)
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:PavanPA
ID: 41732267
Hi Benjamin, Thank you so much for the script, yes it works but what I am looking here is to stop a particular service at server local time 8:00 PM, and we have server in different time zones? IS there any thing we can add to the script to work?

If possible it will be of a good learning to me as well.
0
 

Author Comment

by:PavanPA
ID: 41732269
Or I should use the first script you gave and setup a schedule task to run at local time on all servers...
1
 
LVL 12

Expert Comment

by:Benjamin Voglar
ID: 41756099
For closing service on multiple computers is this the right answer,
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A procedure for exporting installed hotfix details of remote computers using powershell
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
In this Micro Tutorial viewers will learn how they can get their files copied out from their unbootable system without need to use recovery services. As an example non-bootable Windows 2012R2 installation is used which has boot problems.
In this Micro Tutorial viewers will learn how to restore single file or folder from Bare Metal backup image of their system. Tutorial shows how to restore files and folders from system backup. Often it is not needed to restore entire system when onl…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question