Get public IP on a Windows Server via PowerShell

20160614150939Every so often I need a quick way of getting the public IP of a Windows server. There are several ways of doing this but my preferred method leverages PowerShell, specifically the Invoke-WebRequest CMDLET. It sends HTTP, HTTPS, FTP, and FILE requests to a web page or service and responds with elements that you have configured it to capture such as links, images etc.

To obtain the public IP via PowerShell run the simple one-liner below:

PS C:\> (Invoke-WebRequest -uri "http://ipecho.net/plain").Content

Running this command will successfully show your public IP:

20170529132213

There are numerous other services you can call to get the public IP, a few are below:

http://ipinfo.io/ip
http://icanhazip.com
http://ident.me
http://smart-ip.net/myip

Simply replace http://ipecho.net/plain in the PowerShell command above with one of the URLs above and you should get your public IP back in exactly the same way.

References:
Invoke-WebRequest

Change Product Key in Windows Server 2012 via command line

To change the Product Key on Windows Server 2012 and activate it via command line run the following commands below.

To remove all installed keys run the following command:

 slmgr.vbs -upk 

To add the new key, run the command below:

slmgr.vbs -ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

Obviously change XXXXX-XXXXX-XXXXX-XXXXX-XXXXX with your actual key.

And that’s it! The Product Key has been changed and activated successfully. If you have to do this many times it makes sense to script this, so the batch file below achieves all the steps above in one go:

::Remove all installed keys
slmgr.vbs -upk

::Install new product key
slmgr.vbs -ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

I hope this helps you save a bit of time and energy!