Loading
Your Intune Compliance Is Moving to Azure Attestation… and Your Firewall Might Break it
Microsoft is Unifying the Copilot Apps… What IT Admins need to know before September 2026
Remove Device Everywhere – Because Microsoft Thought 3 Portals Was a Good Idea
I Asked Copilot To Make ASCII Art… and It Broke My Soul
AZ-140 Renewal 2025 – What Microsoft Really Tested (and what they didn’t)
It has been a while since I posted something on my blog, I do apologize. I just started with a new client and my schedule has been like a roller coaster. CRAZY!!!
Anyway; I’ve got another Powershell script that you might find interesting.

My last Powershell script was a big success on Reddit. So maybe you’ll like it too. Here’s a way to create a ServiceDesk GUI Tool.
To this day I am still baffled by some companies that lack documentation of their system or configuration. It shouldn’t be that difficult. Documentation helps you, saves you, gets you coffee, informs you and so much more.
At a recent client of mine, they used an SMTP Relay that had a list of IP addresses that was a mile long. Without documentation, you cannot know what those IP addresses are, or are they malevolent?

What I wanted is a script that would export the complete list of IP addresses, ping them if they are alive or not, and if they are alive try to look up their FQDN name.
Did you get that? Let’s start.
I am no Powershell guru nor do I claim to be. I have never had a Powershell course or whatever. This is just me making stuff up on the fly, so I you are a Powershell ultra master; here’s a laugh:
#Here I define the location that I want to export the list
$OutputCSV = "C:\Temp\IPRelay.csv"
#This is the magical export line. If you type $RelayIPList after this you'll get a
#list of IP addresses.
$SMTP = Get-WmiObject IISSmtpServerSetting -namespace "ROOT\MicrosoftIISv2" | Where-Object { $_.name -like "SmtpSVC/1" }
$RelayIPList = @()
For ($CurrentIt = 0; $CurrentIt -lt $SMTP.RelayIpList.Count; $CurrentIt += 4) {
$EndIndex = $CurrentIt + 3
$RelayIPList += $SMTP.RelayIpList[$CurrentIt..$EndIndex] -join "."
}
$RelayIPList = $RelayIPList[20..($RelayIPList.Count - 1)]
#$RelayIPList
#Here I start to ping every IP address that is exported.
#If an IP address answers it will look up the dns name.
ForEach ($RelayIP in $RelayIPList){
$pingtest = Test-Connection -ComputerName $RelayIP -Quiet -Count 1 -ErrorAction SilentlyContinue
If ($pingtest) {
#I have a split here. That is because at first I didn't want the domain name
#to show up... but then I changed my mind.
$dnsName = [System.Net.Dns]::GetHostEntry("$RelayIP").Hostname#.Split('.')[0]
$Output += "$RelayIP Online $dnsName`n"
}
Else {
$Output += "$RelayIP Not Online`n"
}
}
$Output | Out-File $OutputCSV -Encoding utf8 -AppendI had very little time to do this. The ‘n at the and is to give the line a BREAK. I didn’t care much about the code itself more about the result of it.
And if I have to be honest; for someone who isn’t a Powershell master… it still isn’t that good but it’s free for you to have.

I would love to hear feedback.
Thanks for reading.
Cheers,
Engin
Engin SoysalMicrosoft MVP and Microsoft Certified Trainer, sharing practical experience with Azure, Microsoft Intune and endpoint engineering.
43 stories · read them all
0 Comments