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

Upcoming Posts

Sorry - nothing planned yet!

Don't miss it - Subscribe by RSS


MCM


MVP


FoRG


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

  • A Page Split in SQL Server - the Good, the Nasty and the Smart
  • Service Packs and Updates - Tables and Download links
  • Working with tabs and spaces in SSMS (Day 34)
  • Availability Group issues fixed with Alerts
  • Interview questions
  • Working with the registry from within SQL Server
  • CLR Strict Security in SQL 2017
  • Using a gMSA with SQL Server
  • Using Bookmarks to navigate code in SSMS (Day 24)
  • Checking for temporary table existence

Archives

Categories

Tags

Advanced Certifications AG analytic functions assign sequential number automation Availability Group Back To Basics Batch Separator clustered index code smells Connection Dialog Cumulative Updates Denali Functions gMSA Goals import file Job myth New blogger order by Performance Performance Test physical tally table Pivot Primary Quirky Update Replica Scalar UDF Inlining Service Packs spaces split string SQL SQL Server SQL Tools SSMS SSMS Tips Strip Time T-SQL Tuesday tabs tally table temporary table existence TSQL Tuesday virtual tally table wrapup

Blogroll

  • Andy Leonard
  • Kimberly Tripp
  • Aaron Bertrand
  • Tim Ford
  • Greg Low
  • Jason Brimhall
  • Benjamin Nevarez
  • Kevin Kline
  • Rob Farley
  • Gail Shaw
  • Hugo Kornelis
  • Jen McCown
  • Jonathan Kehayias
  • Jorge Segarra
  • Gianluca Sartori

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:

  • Twitter
  • LinkedIn
  • Email
  • Print
  • More
  • Facebook
  • Pinterest
  • 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 post Cancel reply

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

Powered by WordPress Web Design by SRS Solutions © 2021 Wayne Sheffield Design by SRS Solutions
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.
%d bloggers like this:

    By continuing to use the site, you agree to the use of cookies. more information

    The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

    Close