Last active
June 1, 2023 16:01
-
-
Save junecastillote/202840c763095b8400595bf5c05f5392 to your computer and use it in GitHub Desktop.
Get IIS SMTP Server Relay IP Address List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function GetIISSmtpRelayIPList { | |
param ( | |
# virtual smtp server name | |
[parameter()] | |
[string]$smtpName = "SmtpSVC/1", | |
# computer name | |
[parameter()] | |
[string]$computerName = $env:COMPUTERNAME | |
) | |
# Get the IISSmtpServerSetting object using WMI | |
$vSmtp = Get-WmiObject -computerName $computerName IISSmtpServerSetting -namespace "ROOT\MicrosoftIISv2" | Where-Object {$_.name -eq $smtpName} | |
#Create empty variable to store the IP list | |
$AllowedIp = @() | |
#iterate through the value of $vSmtp.RelayIpList which is of type 'System.Byte' | |
$i=0 | |
While ($i -lt $vSmtp.RelayIpList.Count) { | |
#reconstruct to IP address format | |
$AllowedIp += $vSmtp.RelayIpList[$i..($i+3)] -join "." | |
$i+=4 | |
} | |
# Skip the first 0 to 19 IP address, those are the defaults. | |
$AllowedIp = $AllowedIp[20..($AllowedIp.Count)] | |
return $AllowedIp | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment