Showing posts with label Schedulars. Show all posts
Showing posts with label Schedulars. Show all posts

Monday, July 23, 2018

Restart windows server at specific time

I day today activities, you may need to restart your servers daily, weekly etc. when you have so many servers, it may be a vert cumbersome task.
1. Restart server - create a script
2. run task at specific time  -create task schedular


1. below is the script
---------------------------------------
shutdown /r /f
----------------------------------------


2. create task

a.) General tab , tick "Run whether user log or not" and "Run with highest privileges"
b.) Trigger give time you need to execute the script

refer previous article to set up command
   https://cgenit.blogspot.com/2018/07/stop-iis-with-task-schedular.html

Stop IIS with Task Schedular


1. create a powershell with needed commands
2. create basic task with executing the powershell script with highest privileges and with whether user log or not.


Below is the powershell script

----------------------------------
# Start-Process powershell -Verb runAs

If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))


$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}

# Do your adminy thing here...

iisreset /stop




2. Create Basic task

a.) General tab , tick "Run whether user log or not" and "Run with highest privileges"
b.) Trigger give time you need to execute the script
c.) Actions
     program script  = powershell.exe
    Arguments = -ExecutionPolicy Bypass  C:\Project\stopIIS.ps1








Tuesday, July 17, 2018

Windows task Schedulars

It was pretty hard to find a command to enable and disable the windows task schedulers.
Only way to do that was to rename the job files. Job files basically resides in "Task" folder.

This folder my have below paths
C:\Windows\Tasks
or
C:\Windows\System32\Tasks\


I renamed task files. Better to backup those files before doing this.

let's take a task scheduler created inside "Test" folder and name of the task as "TestPS"

the of the file would look like
C:\Windows\System32\Tasks\Test\TestPS


Disable  - rename as .bak
---------
move "C:\Windows\System32\Tasks\Test\TestPS" "C:\Windows\System32\Tasks\Test\TestPS.bak"

Enable  - rename as original file
------------------------------
move "C:\Windows\System32\Tasks\Test\TestPS.bak" "C:\Windows\System32\Tasks\Test\TestPS"