Exchange the PowerShell Settings script scheduled task

Source: Internet
Author: User

In our daily management, the most common is the administrator to schedule a task scheduled to start a script, in this section, we look at how to Windows schedule tasks to set some basic tasks

How to open a Windows to schedule a task, take a look at the specific steps below:

1. Open Windows Scheduled Tasks by using the following steps (Windows Server R2), Server Manager à tools à Task Scheduler

650) this.width=650; "title=" 01.png "style=" height:465px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m02/59/85/wkiol1tw4fuqcifdaarlecqdhii391.jpg "width=" 720 "height=" 465 "alt=" Wkiol1tw4fuqcifdaarlecqdhii391.jpg "/>

Task Scheduler Panel

650) this.width=650; "title=" 02.png "style=" height:511px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m02/59/89/wkiom1tw4qubxcyaaaoz8_4cnnu738.jpg "width=" 720 "height=" 511 "alt=" Wkiom1tw4qubxcyaaaoz8_4cnnu738.jpg "/>

2. Click " create basic task " in the action bar

3. Enter the distinguished name of the scheduled task in the Name box and click next

650) this.width=650; "title=" 03.png "style=" Float:none; "src=" http://s3.51cto.com/wyfs02/M00/59/85/ Wkiol1tw4fvi-fklaagi0wgrl44646.jpg "alt=" Wkiol1tw4fvi-fklaagi0wgrl44646.jpg "/>

4. Set task trigger frequency, next

650) this.width=650; "title=" 04.png "style=" Float:none; "src=" http://s3.51cto.com/wyfs02/M00/59/89/wKiom1TW4QvQT_ 42aafwfo5exp0625.jpg "alt=" Wkiom1tw4qvqt_42aafwfo5exp0625.jpg "/>

5, set the daily frequency, you can run multiple times a day, click " Next Step "

650) this.width=650; "title=" 05.png "style=" Float:none; "src=" Http://s3.51cto.com/wyfs02/M01/59/85/wKioL1TW4fzzs_ Ksaafzawgq6sy596.jpg "alt=" Wkiol1tw4fzzs_ksaafzawgq6sy596.jpg "/>

6, choose the starting program here, the next step

650) this.width=650; "title=" 06.png "style=" Float:none; "src=" http://s3.51cto.com/wyfs02/M01/59/89/ Wkiom1tw4qub7a23aafqbyvsjai940.jpg "alt=" Wkiom1tw4qub7a23aafqbyvsjai940.jpg "/>

7. in the program and script browse to our batch file, click " next "

650) this.width=650; "title=" 07.png "style=" Float:none; "src=" http://s3.51cto.com/wyfs02/M02/59/85/ Wkiol1tw4fzcsp0daafr8a942q4751.jpg "alt=" Wkiol1tw4fzcsp0daafr8a942q4751.jpg "/>

The batch files are as follows:

650) this.width=650; "title=" 08.png "style=" Float:none; "src=" http://s3.51cto.com/wyfs02/M02/59/89/ Wkiom1tw4qui8rxsaacde7oz7vo222.jpg "alt=" Wkiom1tw4qui8rxsaacde7oz7vo222.jpg "/>

PS1 The file information is as follows:

650) this.width=650; "title=" 09.png "style=" height:314px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m00/59/85/wkiol1tw4fzjkqcdaajymi7irs0333.jpg "width=" 720 "height=" 314 "alt=" Wkiol1tw4fzjkqcdaajymi7irs0333.jpg "/>

8. Click Finish to complete the basic task creation

650) this.width=650; "title=" 10.png "style=" Float:none; "src=" http://s3.51cto.com/wyfs02/M00/59/89/ Wkiom1tw4qyc7gkvaahg0upezw0555.jpg "alt=" Wkiom1tw4qyc7gkvaahg0upezw0555.jpg "/>

9. Look at the scheduler in the scheduled task, let's run it manually to see the results .

650) this.width=650; "title=" 11.png "style=" height:514px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m01/59/89/wkiom1tw4sbimfesaan39wpahj8994.jpg "width=" 720 "height=" 514 "alt=" Wkiom1tw4sbimfesaan39wpahj8994.jpg "/>

10. Run the next script manually, right click à run

650) this.width=650; "title=" 12.png "style=" height:232px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m02/59/85/wkiol1tw4hfry5leaag2yzfqwd4568.jpg "width=" 720 "height=" 232 "alt=" Wkiol1tw4hfry5leaag2yzfqwd4568.jpg "/>

11. Viewing the results information, you can see that the scheduled task has done the appropriate action

650) this.width=650; "title=" 13.png "style=" height:436px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m02/59/89/wkiom1tw4sfjy5w_aaqcpebabpo810.jpg "width=" 720 "height=" 436 "alt=" wKiom1TW4SfjY5w_ Aaqcpebabpo810.jpg "/>

The above example is called by a batch process PowerShell , and then in PowerShell called in Exchange command to run, run directly below the PowerShell script test to see the effect:

Create a new task plan below

650) this.width=650; "title=" 14.png "style=" Float:none; "src=" http://s3.51cto.com/wyfs02/M00/59/85/ Wkiol1tw4hfsupe3aagmmichnnq812.jpg "alt=" Wkiol1tw4hfsupe3aagmmichnnq812.jpg "/>

The other steps are basically the same, and then to this step, the program and script enter the following command:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe-command "." C:\Program Files\Microsoft\Exchange Server\v15\bin\remoteexchange.ps1 '; Connect-exchangeserver-auto; C:\Script\Report02.ps1 "

650) this.width=650; "title=" 15.png "style=" Float:none; "src=" http://s3.51cto.com/wyfs02/M00/59/89/ Wkiom1tw4sfwhqlaaagvy_3fwl8062.jpg "alt=" Wkiom1tw4sfwhqlaaagvy_3fwl8062.jpg "/>

clicking Next will pop up the following box, click " is a "

650) this.width=650; "title=" 16.png "style=" Float:none; "src=" http://s3.51cto.com/wyfs02/M01/59/85/ Wkiol1tw4hfxsuthaafdl8xtzkw975.jpg "alt=" Wkiol1tw4hfxsuthaafdl8xtzkw975.jpg "/>

Click "Finish " complete the creation of basic planning tasks

650) this.width=650; "title=" 17.png "style=" Float:none; "src=" http://s3.51cto.com/wyfs02/M01/59/89/ Wkiom1tw4sfbpu9laahebhx6bng112.jpg "alt=" Wkiom1tw4sfbpu9laahebhx6bng112.jpg "/>

Once the basic task has been created, we can manually run the next task to receive e-mail:

650) this.width=650; "title=" 18.png "style=" height:426px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m02/59/85/wkiol1tw4hjhr80paaqt2lonnjs642.jpg "width=" 720 "height=" 426 "alt=" Wkiol1tw4hjhr80paaqt2lonnjs642.jpg "/>

How do these scripts work?

in this case, the trial statement is much more and looks a bit strange. What we're actually going to do is dispatch PowerShell.exe and then use the -command parameter to execute multiple statements. Here we should note that the script has multiple lines and each statement is separated by semicolons.

The first thing we do is navigate to server bin remoteexchange.ps1 file, This file initializes some exchange Shel variables and imports exchange special features.

the next line of script uses the Connect-exchangeserver Calling Parameters -auto Connection Exchange server, allowing from local AD the best in the site Exchange Server Load Exchange Management Shell environment.

Best, by Exchange Management Shell executes our specified script file.

when using this method, ensure that the scheduled task runs the account owning Exchange permissions for the organization to manage access. Similarly, when the server is enabled for user Account Control (UAC) , you may need to enable the highest privilege run scheduled task in the Scheduled Tasks option, and we also want to enable the user to run regardless of whether they log on or not, such as:

650) this.width=650; "title=" 19.png "style=" Float:none; "src=" Http://s3.51cto.com/wyfs02/M02/59/89/wKiom1TW4SiSk_ Dtaajhkmoagho870.jpg "alt=" Wkiom1tw4sisk_dtaajhkmoagho870.jpg "/>

More examples of Scheduled tasks:

In the previous example, we were installing a Exchange run on the server that manages the tools. So how do you run scripts remotely on a workgroup or on a server that doesn't have administrative tools installed? The answer is yes, we just need to be able to run on a computer with PowerShell v2 and a later version.

The basic syntax is as follows:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe-command "$s = new-pssession–configurationname Microsoft.exchange-connectionuri http://mbx01.corp.robin.com/PowerShell/; Import-pssession $s; C:\Script\Report02.ps1 "

The above command only requires us to create a scheduled task, in the Program and script box to fill in the above script!

This article from "Robin's Home" blog, declined reprint!

Exchange the PowerShell Settings script scheduled task

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.