THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

The Rambling DBA: Jonathan Kehayias

The random ramblings and rantings of frazzled SQL Server DBA

Getting Partition Offset information with Powershell

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:

image

The code for the HTML report is attached to this blog post.

Published Monday, March 01, 2010 11:53 PM by Jonathan Kehayias

Attachment(s): Partition Alignment Report.zip

Comments

 

SQLRockstar said:

are those disks dynamic, or basic?

March 2, 2010 7:15 AM
 

James O'Neill said:

Actually one of the nice things about get-WmiObject is that the computer name parameter can be an array, so you do it without the loop

Get-WmiObject Win32_DiskPartition -ComputerName "Server2","Server2" | select Name, Index, BlockSize, StartingOffset

March 2, 2010 7:34 AM
 

Jonathan Kehayias said:

SQLRockstar,

They are all basic disks.  I didn't say I was providing correctly configured example output in my post, I know they are all jacked up.  :-)

James,

Thanks, that is awesome and something I didn't know.  I can definitely make some good use of that piece of information now that I know it.

March 2, 2010 9:16 AM
 

Ronald Dameron said:

Nice! This script will be very useful to me also. You can also loop through a list of servers to run the gwmi command using a foreach loop and the get-content cmdlet. I have a couple of examples on my blog. Click on PowerShell label to see them.  

March 3, 2010 6:41 AM
 

SQLAJ said:

I have been working a lot with Powershell also and recently (this morning) was playing around with diskpart from @PaulRandal blog.

When I first saw the wmic reference I knew there was a way using Powershell, you just saved me some time!

Thanks

March 17, 2010 5:27 PM
Anonymous comments are disabled

This Blog

Syndication

Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement