Before we tell the basics, now we're going to start writing the most elementary script.
There are a lot of scripting tools, there are text documents, there are PowerShell Ise,powershell studio, etc., here the system comes with PowerShell ISE
Here you still have to remember to run as an administrator, or the lack of sufficient permissions to cause the command to run failed
OK, let's find the most common command, assuming we want to query the previous day's Exchange mail queue for information such as spam.
So first, the ISE is not an Exchange-aware command by default, so you need to add the Exchange snap-in first
Then enter the command to query the message queue
Because the front-end has multiple servers, the default Get-messagetrackinglog can only be queried in the current server, so multiple servers need to be passed in as objects
Then increase the number of returns limit, prevent exceeding the maximum value, cause cannot display
and increase the time limit.
When when, press F5 to run a bit
Well, it's going to work, then continue to optimize
Because of the current value of the time here, so every time is June 4 to June 5, can not be modified every time this, we write the current date minus one day good
Try it, no problem.
Next, save this file as a. ps1 format OK
So how to use this script, when you need to query, open the PowerShell window directly, run the PS1 file can be
Of course, if your mail execution is also possible, but the execution will automatically close the window, you can add a paused command in the script to prevent closing
All right, I'll introduce you to this in three minutes today, and you can write the usual commands.
First PowerShell script--powershell three minutes (ix)