If you're ever in need of using an Amazon AWS's public DNS name from within a script running on an EC2 instance, here's a quick way to get it using PowerShell. This technique uses the Instance Metadata that every EC2 instance has available. I'm using the parameterBasicParsing here because if running this on Server Core without IE installed, it will bomb.

((Invoke-WebRequest -Uri http://169.254.169.254/latest/meta-data/public-hostname -UseBasicParsing).RawContent -split "`n")[-1]

Join the Jar Tippers on Patreon

It takes a lot of time to write detailed blog posts like this one. In a single-income family, this blog is one way I depend on to keep the lights on. I'd be eternally grateful if you could become a Patreon patron today!

Become a Patron!