-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-DpDiskDetails.ps1
47 lines (41 loc) · 1.12 KB
/
Get-DpDiskDetails.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
<#
.SYNOPSIS
Retrieves detailed information about a disk using Diskpart.
.DESCRIPTION
The Get-DpDiskDetails function retrieves detailed information about a disk using Diskpart utility. It takes the DiskNumber as a parameter and returns an object containing various disk attributes.
.PARAMETER DiskNumber
Specifies the disk number for which to retrieve the details.
.EXAMPLE
Get-DpDiskDetails -DiskNumber 0
Retrieves detailed information about disk number 0.
.NOTES
Author: Your Name
Date: 2024-01-18
#>
Function Get-DpDiskDetails
{
param(
[parameter(mandatory=$true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[Alias('ID','DiskID')]
[int]$DiskNumber
)
Process {
$RegExKeyValue = '^(.+?)\s*:(?:\s*)?(.+)'
$DiskpartCommand = @"
Select Disk $DiskID
Det Disk
"@
$ReturnValue = $DiskpartCommand | diskpart.exe
$DiskAttributes = [ordered]@{}
Foreach ( $Line in $ReturnValue )
{
If ( $line -match $RegExKeyValue )
{
$DiskAttributes[$matches[1]] = $matches[2]
}
}
[PSCustomObject]$diskAttributes
}
}