Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The first PowerShell script-- PowerShell for three minutes (9)

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

After going through the basics, let's start to write a rudimentary script.

There are many tools to write scripts, including text documents, PowerShell ISE,PowerShell Studio and so on. Here we choose the PowerShell ISE that comes with the system.

Here, you should still remember to run as an administrator, otherwise it is easy to cause the command to fail due to insufficient permissions.

OK, let's find the most commonly used command. Suppose we want to query the previous day's Exchange mail queue to determine spam and other information.

So first of all, by default, ISE does not recognize Exchange commands, so you need to add an Exchange snap-in first

Then enter the command to query the mail queue

Since there are multiple servers at the front end, 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 limit on the number of returns to prevent the maximum value from being exceeded, resulting in a failure to display

And increase the time limit.

Dangdang, press F5 to run it.

Well, it can be used, and then we will continue to optimize it.

Because of the current value of the time here, it is from June 4 to June 5 every time, so we can't modify this every time. Let's write the current date minus one day.

I tried it. No problem.

Next, save the file in .ps1 format.

So how do you use this script? when you need to query, just open the PowerShell window and run the ps1 file.

Of course, it's OK if your email is executed, but the window will be closed automatically after execution, so you can add a paused command to the script to prevent it from closing.

All right, that's all for today's three minutes. Hurry up and write down the common commands.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report