-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-DpVolume.ps1
79 lines (69 loc) · 2.1 KB
/
Get-DpVolume.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<#
.SYNOPSIS
Retrieves information about disk volumes using Diskpart.
.DESCRIPTION
The Get-DpVolume function retrieves information about disk volumes using Diskpart utility. It can retrieve information for a specific disk or for all volumes on the system.
.PARAMETER DiskNumber
Specifies the disk number for which to retrieve volume information. If not specified, information for all volumes will be retrieved.
.EXAMPLE
Get-DpVolume -DiskNumber 1
Retrieves volume information for disk number 1.
.EXAMPLE
Get-DpVolume
Retrieves volume information for all volumes on the system.
.INPUTS
None. You cannot pipe input to this function.
.OUTPUTS
System.Management.Automation.PSCustomObject. The function returns a custom object with the following properties:
- Number: The volume number.
- Driveletter: The assigned drive letter.
- Label: The volume label.
- FileSystem: The file system type.
- Type: The volume type.
- Size: The volume size.
- Status: The volume status.
- BootType: The boot type.
.NOTES
This function requires administrative privileges to run Diskpart utility.
#>
Function Get-DpVolume {
[CmdletBinding()]
param
(
[parameter(mandatory = $false,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[Alias('ID', 'DiskID')]
[int]$DiskNumber
)
Process {
[Regex]$RegEx = 'Volume\s*(\d+)\s{4,5}([A-Z\s])\s{3}(.+)\s(NTFS|FAT32|FAT|exFAT|ReFS)\s+(\w+)\s+(\d+\s\wB)\s+(\w+)\s{1,2}(.+)$'
If ( $DiskNumber ) {
$DiskpartCommand = @"
Select Disk $DiskNumber
Det Disk
"@
}
else {
$DiskpartCommand = @"
list Volume
"@
}
$ReturnValue = $DiskpartCommand | diskpart.exe
foreach ( $line in $ReturnValue ) {
if ( $line -match $RegEx ) {
$volume = [ordered]@{
Number = $matches[1]
Driveletter = $matches[2]
Label = $matches[3]
FileSystem = $matches[4]
Type = $matches[5]
Size = $matches[6]
Status = $matches[7]
BootType = $matches[8]
}
[PSCustomObject]$Volume
}
}
}
}