Paul Randal recently blogged about Using diskpart and wmic to check disk partition alignment. Lately, I have been writing A LOT of Powershell scripts at my new job, primarily because the size of the environment makes it next to impossible to work through all of the servers one at a time, so automating the work with Powershell has made things much more manageable. In his blog post, Paul shows how to use WMIC to get the partition offset information for a server. To do this in Powershell is really quite simple to do in one line:
Get-WmiObject Win32_DiskPartition -ComputerName "ServerName" | select Name, Index, BlockSize, StartingOffset
This will output the information for a single server in a text format similar to the following:
Name Index BlockSize StartingOffset
---- ----- --------- --------------
Disk #2, Partition #0 0 512 65536
Disk #0, Partition #0 0 512 32256
Disk #0, Partition #1 1 512 32901120
Disk #1, Partition #0 0 512 32256
Disk #1, Partition #1 1 512 52436160000
This can easily be hooked into a loop to work across multiple servers:
$Targets = "server1", "Server2"
$Targets | % {
Get-WmiObject Win32_DiskPartition -ComputerName $_ | select SystemName, Name, Index, BlockSize, StartingOffset | Format-Table}
In the above script the % is a alias for the ForEach-Object command that loops over each of the servers in the list. The $_ contains the value of the current object in the list in scope for the loop. This can be really useful in large environments where you need to look at the offset information on all of the servers.
This is about as simple as it can get, but how about adding additional information into the mix like the physical disk information, and logical drive information under the partitions? To do this other WMI classes are required and the Powershell Guy has a script on his blog that shows how to do the related queries locally. Merging this with the HTML code from Virtual-Al’s Workstation Audit Script, a pretty HTML report can be built for a list of servers:
The code for the HTML report is attached to this blog post.