Solved

How to restart specified service via task scheduler in windows sever 2008

Posted on 2014-09-22
19
981 Views
Last Modified: 2014-09-30
I want to restart MS Exchange Transport services . I have scheduled one task for every sunday at 06:00 AM in my TASKS Server but it is not running.

Please advise
 I am using powershell to do this.

Get-WmiObject -ComputerName  SRV-s3011 -Class Win32_Service -Filter "Name='MSExchangeTransport'" | Restart-Service -force

Please help
0
Comment
Question by:SAIMSKY ADMIN
  • 10
  • 8
19 Comments
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40336791
Try using this:

Get-Service -ComputerName SRV-s3011 -Name MSExchangeTransport | Restart-Service -force

Also make sure the service is running with an account that has permissions to restart that service, Set it to run if user is logged in or not, and make sure you input the path to the script even though it is optional.
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40336806
Here is a guide to set Powershell scripts as scheduled tasks

http://community.spiceworks.com/how_to/show/17736-run-powershell-scripts-from-task-scheduler
0
 
LVL 4

Expert Comment

by:akalyan911
ID: 40336809
Hi..

Here is the best option over the command line..
Type one of the following:

To start a service, type:

net startservice

To stop a service, type:

net stopservice

To pause a service, type:

net pauseservice

To resume a service, type:

net continueservice

----------------
Value      Description
net start
Starts a service.
net stop
Stops a service.
net pause
Pauses a service.
net continue
Continues a service that has been paused.
service
Specifies the name of service.
0
 

Author Comment

by:SAIMSKY ADMIN
ID: 40336819
I have to run remotely ... from sSRV-Task220  to SRV-s3011 , Di i need to just copy above  given command to .ps1 file
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40336824
Yes, just copy the above command and be sure to go through the guide to make sure it starts correctly.

 It may not be running because of Execution Policy rules and credentials. Also, be sure to fill in the Start in (optional) field and input the path to the folder. I have noticed that sometimes, scripts do not run when the path is not defined.
0
 

Author Comment

by:SAIMSKY ADMIN
ID: 40336837
Please check screen shot if it is correct.
restart.JPG
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40336851
that may work but you should only need to do

powershell.exe c:\bats\.......

You also may have to add "-ExecutionPolicy Bypass" if it does not run. Did you look through the guide?
0
 

Author Comment

by:SAIMSKY ADMIN
ID: 40336879
how to pre-check this command/ps script , i do not want to run service now.
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40336897
change the computer name to your computer and change the service name to spooler then run the scheduled task. Make sure it runs correctly then change it back.

Check on your computer that the print spooler service was restarted.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:SAIMSKY ADMIN
ID: 40336915
Get-Service -ComputerName ADA-3E145085S-L  is  working fine but 2nd path I am getting error.

Restart-Service : Service 'Print Spooler (Spooler)' cannot be stopped due to the following error: Cannot open Spooler service on computer 'ADA-3E145085S-L'.
At line:1 char:59
+ Get-Service -ComputerName ADA-3E145085S-L -Name Spooler | Restart-Service -force
+                                                           ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (System.ServiceProcess.ServiceController:ServiceController) [Restart-Service], ServiceCommandException
    + FullyQualifiedErrorId : CouldNotStopService,Microsoft.PowerShell.Commands.RestartServiceCommand
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40336922
You have to run the script with elevated privileges.
0
 

Author Comment

by:SAIMSKY ADMIN
ID: 40336924
I am running with admin rights
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40336927
in the scheduled task setup, did you select the box that says run with highest privileges? What account do you have set to run the task?

If you are trying to test the script by itself, you have to open powershell as admin by right clicking
0
 

Author Comment

by:SAIMSKY ADMIN
ID: 40336936
yes , i opened the powershell as admin by right clicked
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40336955
OK, does your account that you logged into the server with have Domain Admin privileges?
0
 

Author Comment

by:SAIMSKY ADMIN
ID: 40336960
yes
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40337232
To be clear, this is what you are pasting into an elevated powershell window

powershellsnip.PNG
0
 
LVL 16

Accepted Solution

by:
Joshua Grantom earned 500 total points
ID: 40337259
try this one to see if it still gives an error

Restart-Service -InputObject $(Get-Service -Computer SRV-s3011 -Name MSExchangeTransport)

Open in new window

0
 

Author Closing Comment

by:SAIMSKY ADMIN
ID: 40351688
thanks
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now