-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-DpDisk.ps1
44 lines (37 loc) · 1.49 KB
/
Get-DpDisk.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
<#
.SYNOPSIS
Retrieves information about disks using Diskpart.
.DESCRIPTION
The Get-DpDisk function uses Diskpart to retrieve information about disks on the system. It parses the output of the "List Disk" command and extracts the disk number, status, size, free space, dynamic status, and GPT status for each disk.
.PARAMETER None
This function does not accept any parameters.
.EXAMPLE
Get-DpDisk
This example retrieves information about disks using Diskpart and displays the results.
.OUTPUTS
The function outputs a custom object for each disk, containing the following properties:
- DiskNumber: The disk number.
- Status: The status of the disk.
- Size: The size of the disk.
- Free: The amount of free space on the disk.
- Dynamic: Indicates whether the disk is dynamic (True) or not (False).
- GPT: Indicates whether the disk is using GPT (True) or not (False).
#>
Function Get-DpDisk {
[cmdletBinding()]
param()
[Regex]$RegEx = "(?:Disk|Datenträger)\s(\d{1,3})\s{1,}(\w{1,})\s{1,}(\d{1,}\s[KMGTP]{0,1}B)\s{1,}(\d{1,}\s[KMGTP]{0,1}B).{3}(.).{4}(\*| )"
$ReturnValue = "List Disk" | diskpart.exe
foreach ( $line in $ReturnValue ) {
if ( $line -match $RegEx ) {
[PSCustomObject]@{
DiskNumber = $matches[1]
Status = $matches[2]
Size = $matches[3]
Free = $matches[4]
Dynamic = $( If ( $matches[5] -eq '*' ) { $true } else { $false })
GPT = $( If ( $matches[6] -eq '*' ) { $true } else { $false })
}
}
}
}