Monday, July 23, 2018

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








No comments:

Post a Comment