SAIMSKY ADMIN
asked on
How to restart specified service via task scheduler in windows sever 2008
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
Please advise
I am using powershell to do this.
Get-WmiObject -ComputerName SRV-s3011 -Class Win32_Service -Filter "Name='MSExchangeTransport
Please help
Here is a guide to set Powershell scripts as scheduled tasks
http://community.spicework s.com/how_ to/show/17 736-run-po wershell-s cripts-fro m-task-sch eduler
http://community.spicework
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.
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.
ASKER
I have to run remotely ... from sSRV-Task220 to SRV-s3011 , Di i need to just copy above given command to .ps1 file
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.
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.
ASKER
Please check screen shot if it is correct.
restart.JPG
restart.JPG
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?
powershell.exe c:\bats\.......
You also may have to add "-ExecutionPolicy Bypass" if it does not run. Did you look through the guide?
ASKER
how to pre-check this command/ps script , i do not want to run service now.
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.
Check on your computer that the print spooler service was restarted.
ASKER
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.Ser viceContro ller:Servi ceControll er) [Restart-Service], ServiceCommandException
+ FullyQualifiedErrorId : CouldNotStopService,Micros oft.PowerS hell.Comma nds.Restar tServiceCo mmand
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.Ser
+ FullyQualifiedErrorId : CouldNotStopService,Micros
You have to run the script with elevated privileges.
ASKER
I am running with admin rights
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
If you are trying to test the script by itself, you have to open powershell as admin by right clicking
ASKER
yes , i opened the powershell as admin by right clicked
OK, does your account that you logged into the server with have Domain Admin privileges?
ASKER
yes
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
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.