Asks three independent lookup services in turn until one answers with something that looks like an IPv4 address, so a single dead endpoint does not fail the check. The result is handed to the next runbook step, ready to be compared against the egress address a firewall rule or a SaaS allowlist expects.
powershell
# Get Public IP Address
# Single use case: report the WAN IP this server egresses from
#-----------------------------------------------------------------
function Write-Log {
param($Message)
Write-Host "<WRITE-LOG = `"*$Message*`">"
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ip = $null
foreach ($endpoint in @("https://api.ipify.org", "https://ifconfig.me/ip", "https://icanhazip.com")) {
try {
$ip = (Invoke-RestMethod -Uri $endpoint -TimeoutSec 10 -UseBasicParsing).ToString().Trim()
if ($ip -match "^\d{1,3}(\.\d{1,3}){3}$") {
Write-Log "Public IPv4: $ip (via $endpoint)"
break
}
$ip = $null
} catch { continue }
}
if ($null -eq $ip) {
Write-Log "Could not determine the public IP - no lookup endpoint reachable (proxy/firewall?)."
return
}
# Pass to the next runbook script (ex. compare against expected egress IP)
$store = $ipRun it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in System Administration
Generate a Random Password with PowerShell
2026-08-17Send a Wake-on-LAN Magic Packet with PowerShell
2026-08-17Force a Windows Shutdown with PowerShell
2026-08-17Download and Extract Files with BITS in PowerShell
2026-08-17Check Linux Uptime and Disk Usage over SSH
2026-08-17Automated System Information Gatherer Script
2025-01-14Ready when you are.
Try ServerEngine free for 7 days.