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 "").Content

Running this command will successfully show your public IP:


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

Simply replace in the PowerShell command above with one of the URLs above and you should get your public IP back in exactly the same way.


Get the allocation unit size of an NTFS partition in Server 2012

20170522112224If you’re a SQL Server Pro you will know that the volumes the SQL log and datafiles are stored on should be formatted with a 64K cluster size. This is a SQL Server Best practice as stated in this link.

To find out what the allocation unit size is for a drive run the command below:

fsutil fsinfo ntfsinfo [your drive]

Running the same command on a test system on the E:\ drive I get the following result:

C:\>fsutil fsinfo ntfsinfo E:
NTFS Volume Serial Number :       0x0c76bbd176bbba32
NTFS Version   :                  3.1
LFS Version    :                  2.0
Number Sectors :                  0x00000000013fe7ff
Total Clusters :                  0x0000000000027fcf
Free Clusters  :                  0x0000000000027d5b
Total Reserved :                  0x0000000000000000
Bytes Per Sector  :               512
Bytes Per Physical Sector :       512
Bytes Per Cluster :               65536
Bytes Per FileRecord Segment    : 1024
Clusters Per FileRecord Segment : 0
Mft Valid Data Length :           0x0000000000010000
Mft Start Lcn  :                  0x000000000000c000
Mft2 Start Lcn :                  0x0000000000000001
Mft Zone Start :                  0x000000000000c000
Mft Zone End   :                  0x000000000000cca0
Resource Manager Identifier :     28DB2529-6D43-11E6-80C7-00505693BAC6

As you can see from the above, the Bytes Per Cluster is equal to 65,536 bytes or 64K.

You would have to run this command for every drive that you want to check. I found this handy piece of PowerShell code that gets just the allocation unit size for all disks in the system:

$wql = "SELECT Label, Blocksize, Name FROM Win32_Volume WHERE FileSystem='NTFS'"
Get-WmiObject -Query $wql -ComputerName '.' | Select-Object Label, Blocksize, Name

The result of which would look similar to this on a system running SQL Server:


The results above show which disks are configured with the default 4K allocation unit size and those configured with 64K which are the SQL disks.

How To Determine Your Hard Disks Cluster Size
SQL Server Best Practices Article
Disk Partition Alignment Best Practices for SQL Server
Get Cluster size for all disks and volumes on a Windows machine using powershell and wmi