-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-DpPartition.ps1
49 lines (41 loc) · 1.23 KB
/
Get-DpPartition.ps1
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
<#
.SYNOPSIS
Retrieves information about partitions on a disk using Diskpart.
.DESCRIPTION
The Get-DpPartition function retrieves information about partitions on a disk using Diskpart utility. It takes the DiskNumber as a mandatory parameter and returns an object containing the partition number, type, size, and offset.
.PARAMETER DiskNumber
The DiskNumber parameter specifies the disk number for which to retrieve partition information.
.EXAMPLE
Get-DpPartition -DiskNumber 0
Retrieves information about partitions on disk 0.
#>
Function Get-DpPartition {
[CmdletBinding()]
param
(
[parameter(mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[Alias('ID', 'DiskID')]
[int]$DiskNumber
)
Process {
[Regex]$RegEx = 'Partition\s(\d)\s*(\w*)\s*(\d*\s\wB)\s*(\d*\s\wB)'
$DiskpartCommand = @"
Select Disk $DiskNumber
List part
"@
$ReturnValue = $DiskpartCommand | diskpart.exe
foreach ( $line in $ReturnValue ) {
if ( $line -match $RegEx ) {
$Partition = [ordered]@{
Number = $matches[1]
Type = $matches[2]
Size = $matches[3]
Offset = $matches[4]
}
[PSCustomObject]$Partition
}
}
}
}