Introduction

Recently, I was decommissioning an Exchange Server that had several devices configured to relay emails through it. To identify the devices connecting to the server and sending emails, I checked the SMTP receive logs. I will provide more details about this process in a separate article. I used Log Parser to extract the relevant data from the log files. The result was a poorly formatted text file. I aimed to extract the necessary information using Powershell, but I faced difficulties with the appropriate commands. Since LLMs are well-versed in scripting, I decided to rely on Copilot for Microsoft 365 instead of searching the web for useful commandlets.

This article is part of my Copilot Blog series. You can find additional use cases for Copilot for Microsoft 365 here.

The csv file

The original txt file looked like this:

remote-endpoint      Hits
192.168.0.10:64355   27
192.168.0.10:52327   26
192.168.0.10:60594   26
192.168.0.10:51907   25
192.168.0.15:64677   25
192.168.0.15:60575   24
192.168.0.15:52522   22
192.168.0.15:56471   22
192.168.0.15:56595   21
192.168.0.17:64381   21
192.168.0.20:64281   20

remove the blank characters

My first step was to remove the blank spaces. I chose to use Copilot within Teams because it is the most convenient option for me. I asked Copilot the following:

The command worked as intended. I exported the output to a new file for further use.

remote-endpoint Hits
192.168.0.10:64355 27
192.168.0.10:52327 26
192.168.0.10:60594 26
192.168.0.10:51907 25
192.168.0.15:64677 25
192.168.0.15:60575 24
192.168.0.15:52522 22
192.168.0.15:56471 22
192.168.0.15:56595 21
192.168.0.17:64381 21
192.168.0.20:64281 20

Delete the Port from the table

I imported the txt file using the import-csv command and set the delimiter option to ‘space’. Then, I removed the port from the remote-endpoint column:

The final result looks like this. It is displayed only in Powershell and has not been exported:

Add up everytime you find a similar value

I want to count hits for each IP address that occurs multiple times.

Export the result

And I was satisfied with the result:

The export failed. I then verified the object’s type:

I asked Copilot for help because I am unfamiliar with working with this type of object.

This was exactly what I needed. I was able to export the information to a CSV file:

Conclusion

Copilot assisted me in finding a solution to a problem I encountered. I had to make minor adjustments to the commandlets provided to make them fit into my complete script. But it helped me a lot to make progress. While there may have been alternative approaches to the solution, I am currently satisfied with the outcome.

I hope you enjoed this article!

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Consent Management Platform von Real Cookie Banner