Skip to posts
  • Publications
  • Code Library
  • Events
  • Presentations
  • Who Am I?
  • Copyright

Wayne Sheffield

My blog about SQL Server
  • Home
  • Publications
  • Code Library
  • Events
  • Presentations
  • Who Am I?
  • Copyright
  • Latest Posts
  • Latest Comments


MCM


MVP

(2017-2022)

Top 50 SQL blog 2018

Recent Posts

  • Availability Group issues fixed with Alerts
  • Using Google Chrome with SSRS
  • Speakers wanted for the Richmond (VA) SQL Server Users Group – 2020
  • T-SQL Tuesday #120 – Recap
  • T-SQL Tuesday #120 – What were you thinking? – Invitation

Top Posts

  • Checking for temporary table existence
  • Using a gMSA with SQL Server
  • Using the Full Screen Mode in SSMS (Day 33)
  • Primary Replica Jobs
  • ORDER BY Clause with clustered index
  • A Month of PowerShell – Day 25 (Integrity Checks)
  • SQLCMD Mode (Day 8)
  • Object Explorer Details (Day 21)
  • Using the SSMS Web Browser (Day 25)
  • A Month of PowerShell – Day 6 (Exporting and Importing)

Archives

Categories

Tags

2020 absolute values (ABS()) Advanced Certifications analytic functions assign sequential number automation Availability Group Back To Basics case-sensitive CLR String Security clustered index common table expression Data Movement deadlock analysis Denali Double-Hop efficiency extracting data from strings Failover Functions Google Chrome import file index analysis myth order by Performance physical tally table Quirky Update Scalar UDF Inlining split string splitting strings SQL SQL 2019 SQL Server SSMS SSMS Tips SSRS String Splitter T-SQL Tuesday tally table Trusted Assembly TSQL Tuesday virtual tally table Why do you do what you do? wrapup

Blogroll

  • Noel McKinney
  • Maria Zakourdaev
  • Gianluca Sartori
  • Aaron Bertrand
  • Gail Shaw
  • Lynn Pettis
  • Benjamin Nevarez
  • Adam Machanic
  • Kendra Little
  • Jen McCown
  • Brad Schulz
  • Jonathan Kehayias
  • Robert Pearl
  • Greg Low
  • Hugo Kornelis

Drive Partition Information

PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#
# -------------------------------------------------------------------------------
# Drive and Partition Information
# -------------------------------------------------------------------------------
#                                MODIFICATION LOG
# -------------------------------------------------------------------------------
# 2012-11-14 WGS Initial Creation.
# 2012-12-05 WGS Add BlockSize, OffsetSectors, Export to delimited file.
# 2013-01-11 WGS Figured out how to do this all inline.
# -------------------------------------------------------------------------------
#
 
FUNCTION Get-DriveLetter($PartPath) {
#Get the logical disk mapping
$LogicalDisks = Get-WMIObject Win32_LogicalDiskToPartition | `
Where-Object {$_.Antecedent -eq $PartPath}
$LogicalDrive = Get-WMIObject Win32_LogicalDisk | `
Where-Object {$_.__PATH -eq $LogicalDisks.Dependent}
$LogicalDrive.DeviceID
}
 
FUNCTION Get-PartitionAlignment {
Get-WMIObject Win32_DiskPartition | `
Sort-Object DiskIndex, Index | `
Select-Object -Property `
@{Expression = {$_.DiskIndex};Label="Disk"},`
@{Expression = {$_.Index};Label="Partition"},`
@{Expression = {Get-DriveLetter($_.__PATH)};Label="Drive"},`
@{Expression = {$_.BootPartition};Label="BootPartition"},`
@{Expression = {"{0:N3}" -f ($_.Size/1Gb)};Label="Size_GB"},`
@{Expression = {"{0:N0}" -f ($_.BlockSize)};Label="BlockSize"},`
@{Expression = {"{0:N0}" -f ($_.StartingOffset/1Kb)};Label="Offset_KB"},`
@{Expression = {"{0:N0}" -f ($_.StartingOffset/$_.BlockSize)}; Label="OffsetSectors"},`
@{Expression = {IF (($_.StartingOffset % 64KB) -EQ 0) {" Yes"} ELSE {"  No"}};Label="64KB"}
}
 
# Hash table to set the alignment of the properties in the format-table
$b = `
@{Expression = {$_.Disk};Label="Disk"},`
@{Expression = {$_.Partition};Label="Partition"},`
@{Expression = {$_.Drive};Label="Drive"},`
@{Expression = {$_.BootPartition};Label="BootPartition"},`
@{Expression = {"{0:N3}" -f ($_.Size_GB)};Label="Size_GB";align="right"},`
@{Expression = {"{0:N0}" -f ($_.BlockSize)};Label="BlockSize";align="right"},`
@{Expression = {"{0:N0}" -f ($_.Offset_KB)};Label="Offset_KB";align="right"},`
@{Expression = {"{0:N0}" -f ($_.OffsetSectors)};Label="OffsetSectors";align="right"},`
@{Expression = {$_.{64KB}};Label="64KB"}
 
$a = Get-PartitionAlignment
 
# Display formatted data on the screen
$a | Format-Table $b -AutoSize
 
# Export to a pipe-delimited file
$a | Export-CSV $ENV:temp\PartInfo.txt -Delimiter "|" -NoTypeInformation
 
# Open the file in NotePad
Notepad $ENV:temp\PartInfo.txt

 

 

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to email a link to a friend (Opens in new window) Email
  • Click to print (Opens in new window) Print
  • More
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Reddit (Opens in new window) Reddit

Like this:

Like Loading...
  • Comments (0)
  • Trackbacks (0)
Leave a comment Trackback

No one has commented yet.

No trackbacks yet.

Leave a Reply to let me know how you liked this postCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Powered by WordPress Web Design by SRS Solutions © 2025 Wayne Sheffield Design by SRS Solutions
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}
%d