Collect server daily check reports with PowerShell, and send messages to administrators

Source: Internet
Author: User
Tags disk usage

-----provide ad\exchange\lync\sharepoint\crm\sc\o365 and other Microsoft product implementation and outsourcing, qq:185426445. Phone 18666943750

Bowen PowerShell program and part of the description from the big to the blog, the original address see the following URL

Collect server daily check reports with PowerShell, and send messages to administrators

http://hubuxcg.blog.51cto.com/2559426/1604582

As a server administrator, routine tasks include frequent checking of each server's hard disk usage, memory, CPU, services, event logs, and so on.

If not without the help of the Scom/zabbix/host monitor and other high-level services or tools, daily manual to a server to view, it is more time-consuming, troublesome thing!

Using PowerShell, collect status information of a server, generate. html file, and notify the person of the same message, the original file is as follows, interested can go directly to the original to do the custom.

https://gallery.technet.microsoft.com/scriptcenter/Get-GeneralSystemReportps1-4d9b5817

https://www.simple-talk.com/sysadmin/powershell/building-a-daily-systems-report-email-with-powershell/

Now after a small modification, the resulting report content is Chinese, and modified to batch collection of multiple server inspection reports.

How to use:

1. Download the attachment script to modify the following content in the script:

1) If you only need to produce. HTML report, do not need to receive mail, you can skip this step, if you need to receive mail, modify the SMTP server address, the sender, the recipient mailbox, and the replica recipient mailbox, and send mail enabled.

[String] $EmailRelay = "Relay.rightdo.net",

[String] $EmailSender = ' [email protected] ',

[String] $EmailRecipient = ' [email protected] ',

[Bool] $SendMail = $True,

False to not send mail, true to send mail

650) this.width=650; "title=" clip_image002 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image002 "src=" http://s3.51cto.com/wyfs02/M00/58/C1/ Wkiol1s75n-b-iynaakv9ouwifg873.jpg "height=" 499 "/>

CC = [email protected]

[Note: Send to the external mailbox we need to open the Exchange Server anonymous relay permissions, we first implemented to the internal mailbox, the end of the article we are talking about how to turn on Exchange anonymous relay]

If necessary, remove the previous "#" and change it to the email address you need

650) this.width=650; "title=" clip_image004 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image004 "src=" http://s3.51cto.com/wyfs02/M00/58/C4/ Wkiom1s75bci1hy1aaffo6md1ek409.jpg "height=" 442 "/>

2) Modify the process information that requires querying the event log and consuming the most memory. The default is the last 3 system and application logs that display the log information as warnings or errors, with the top 10 memory consuming the highest process information. Adjustments can be made according to your own needs.

# # environment Specific-change These # #

$EventNum = 3 # Number of events to fetch for system report

$ProccessNumToFetch = ten # of processes to fetch for system report

650) this.width=650; "title=" clip_image005 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image005 "src=" http://s3.51cto.com/wyfs02/M01/58/C1/ Wkiol1s75olancp6aac03r8fikw419.jpg "height=" 108 "/>

3) in the same directory where this PS file is stored, create a Serverlist.txt file, fill in this file with the name of the server you want to collect, and a host name for one server, such as:

Vmshdc01.rightdo.net

Exshsv01.rightdo.net

Lyncshsv01.rightdo.net

650) this.width=650; "title=" clip_image007 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image007 "src=" http://s3.51cto.com/wyfs02/M01/58/C4/wKiom1S75BKT_ 4ypaadsjvgajek302.jpg "height=" 417 "/>

2. Testing in PowerShell If the script cannot execute, modify the script execution policy

650) this.width=650; "title=" clip_image008 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image008 "src=" http://s3.51cto.com/wyfs02/M02/58/C4/ Wkiom1s75box5gm4aaevasbxfq8398.jpg "height=" 159 "/>

3, create a scheduled task, let the script automatically run at the specified time!

Step 1, Control Panel-all Control Panel items-Administrative Tools-Task Scheduler

650) this.width=650; "title=" clip_image010 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image010 "src=" http://s3.51cto.com/wyfs02/M00/58/C2/ Wkiol1s75ouyy1htaanmyqxo9vk447.jpg "height=" 699 "/>

Step 2, create a basic task ...

650) this.width=650; "title=" clip_image012 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image012 "src=" Http://s3.51cto.com/wyfs02/M00/58/C2/wKioL1S75O-xeaThAAJfDFt_ T1y701.jpg "height=" 609 "/>

Step 3, fill in the name---PowerShell collection server logs, next

650) this.width=650; "title=" clip_image014 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image014 "src=" http://s3.51cto.com/wyfs02/M00/58/C4/wKiom1S75CDQsC_UAAG2_ Vqvzkw306.jpg "height=" 662 "/>

Step 4, select Daily, next to continue

650) this.width=650; "title=" clip_image016 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image016 "src=" http://s3.51cto.com/wyfs02/M01/58/C4/ Wkiom1s75clzjreeaagfom0e2ju616.jpg "height=" 665 "/>

Step 5, define the time of day to perform the task, continue to the next step

650) this.width=650; "title=" clip_image018 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image018 "src=" http://s3.51cto.com/wyfs02/M02/58/C2/ Wkiol1s75pbikuubaagcx2sbmcg804.jpg "height=" 660 "/>

Step 6, start the program, continue to the next step

650) this.width=650; "title=" clip_image020 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image020 "src=" http://s3.51cto.com/wyfs02/M02/58/C4/wKiom1S75Ceio7SvAAGBNO_ Kjtg273.jpg "height=" 663 "/>

Enter at step 7, program, or script

Powershell-file "C:\Get-GeneralSystemReport_Network_51cto.ps1"

650) this.width=650; "title=" clip_image022 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image022 "src=" http://s3.51cto.com/wyfs02/M00/58/C2/ Wkiol1s75pysqusjaag5okqku-a334.jpg "height=" 664 "/>

Step 8, select Yes, next continue

650) this.width=650; "title=" clip_image024 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image024 "src=" http://s3.51cto.com/wyfs02/M02/58/C4/ Wkiom1s75c-sxpgeaajox8vp8xc344.jpg "height=" 664 "/>

Step 9, complete

650) this.width=650; "title=" clip_image026 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image026 "src=" http://s3.51cto.com/wyfs02/M01/58/C4/ Wkiom1s75dlxfyb7aaigshb0nd0633.jpg "height=" 660 "/>

Step 10, select whether or not the user is logged in to run

650) this.width=650; "title=" clip_image028 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image028 "src=" http://s3.51cto.com/wyfs02/M02/58/C4/ Wkiom1s75dfrenosaakv7rnzxto218.jpg "height=" 720 "/>

The. HTML reports generated after execution are as follows:

650) this.width=650; "title=" clip_image030 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image030 "src=" http://s3.51cto.com/wyfs02/M00/58/C4/wKiom1S75DvALtIjAAHj_ Ynruky814.jpg "height=" 784 "/>

If mail is enabled, you receive the following message:

650) this.width=650; "title=" clip_image032 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image032 "src=" http://s3.51cto.com/wyfs02/M00/58/C2/ Wkiol1s75q-qdi23aaebce-rwo8547.jpg "height=" 378 "/>

Description: This method allows you to log on to a server to perform this script in a domain environment, either as a domain administrator or as an account that has all of the server's administrator rights. If the account that is logged on when the script is executed does not have administrator rights for the corresponding server, it cannot be executed. If the permissions of each server are dispersed and do not have administrator privileges, it is recommended that you put the script analysis on each server and then execute the script or set the scheduled task on each server.

Let's move on to how anonymous relaying is set up,

Because the way that our PowerShell script uses SMTP calls is anonymous, including sending messages inside and outside, you might not be able to send messages outside if you don't send them anonymously. We'd better not set up anonymous access in the default accept connector, so we need to set up a new accept connector and accept anonymous access. So we follow the corresponding steps to set up, our new drug to build an acceptance connector,

Step 1, first login to the EX server open the EAC Administration Web page, navigate to mail Flow-Receive connector:

650) this.width=650; "title=" clip_image034 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image034 "src=" Http://s3.51cto.com/wyfs02/M01/58/C2/wKioL1S75RGxfsedAAEhmA4Oi_ W197.jpg "height=" 491 "/>

Step 2, new Receive connector, name-relay, role-front end transport, type-Internal

650) this.width=650; "title=" clip_image036 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image036 "src=" http://s3.51cto.com/wyfs02/M01/58/C4/ Wkiom1s75egxhetfaadxq4vlcqg582.jpg "height=" 559 "/>

Step 3, edit the remote network settings, IP segment set to internal network segment 10.10.10.1-10.10.10.254

650) this.width=650; "title=" clip_image038 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image038 "src=" Http://s3.51cto.com/wyfs02/M02/58/C4/wKiom1S75EWyu3rfAAIGg_ Uevfg744.jpg "height=" 662 "/>

650) this.width=650; "title=" clip_image040 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image040 "src=" http://s3.51cto.com/wyfs02/M02/58/C2/ Wkiol1s75rjaawg7aaeqf3nlxgs985.jpg "height=" 575 "/>

Step 4,

Authentication Select Basic authentication, Integrated Windows authentication

Permission Group Select Exchange Server, Legacy Exchange Server, Exchange user, anonymous user

650) this.width=650; "title=" clip_image042 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image042 "src=" http://s3.51cto.com/wyfs02/M00/58/C2/ Wkiol1s75rqbwjx4aacjwuclrf4050.jpg "height=" 540 "/>

Step 5, FQDN:relay.rightdo.net, create a new relay.rightdo.net a record

650) this.width=650; "title=" clip_image044 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image044 "src=" http://s3.51cto.com/wyfs02/M01/58/C2/ Wkiol1s75ryxgh4laaetcypgdos069.jpg "height=" 530 "/>

650) this.width=650; "title=" clip_image046 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image046 "src=" http://s3.51cto.com/wyfs02/M00/58/C4/ Wkiom1s75e7rcvr7aah18gye7ka204.jpg "height=" 532 "/>

Step 6, we want to set the current Receive connector to be anonymous can relay, need to use PowerShell script, Powellshell script content is as follows:

[PS] C:\windows\system32>get-receiveconnector "Relay" | Add-adpermission-user "NT authority\anonymous LOGON"-extendedrights "Ms-exch-smtp-accept-any-recipient"

650) this.width=650; "title=" clip_image048 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image048 "src=" http://s3.51cto.com/wyfs02/M01/58/C2/ Wkiol1s75stzimt9aaepbgiynlu799.jpg "height=" 370 "/>

Step 7, to this end, our anonymous RELAY has been set to complete, if there are multiple servers need to use the SMTP RELAY will need to each server to do the same settings:

We then conducted a test to test the anonymous relay to the external machine to send the message, tested and found that the message could be relay any domain name:

650) this.width=650; "title=" clip_image050 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image050 "src=" http://s3.51cto.com/wyfs02/M02/58/C5/ Wkiom1s75ffjmz13aaku9pekdqe862.jpg "height=" 564 "/>

Step 8, set up the anonymous relay, the test, found that our external QQ mailbox also received a server report.

650) this.width=650; "title=" clip_image052 "style=" Border-top:0px;border-right:0px;border-bottom:0px;border-left : 0px; "border=" 0 "alt=" clip_image052 "src=" http://s3.51cto.com/wyfs02/M02/58/C5/ Wkiom1s75fyyzbuhaajw3jhrpqm189.jpg "height=" 659 "/>

This article is from the "Zhou Ping Microsoft Technology Exchange Platform" blog, please be sure to keep this source http://yuntcloud.blog.51cto.com/1173839/1605486

Collect server daily check reports with PowerShell, and send messages to administrators

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.