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 -UseBasicParsing).RawContent -split "`n")[-1]