Private/Disk/Get-DiskWithSystemPartition.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
<#
.SYNOPSIS
Gets the Disk containing the SYSTEM partition
 
.DESCRIPTION
Gets the Disk containing the SYSTEM partition
 
.LINK
https://osd.osdeploy.com/module/functions/storage/Get-DiskWithSystemPartition
 
.NOTES
19.12.9 Created by David Segura @SeguraOSD
#>

function Get-DiskWithSystemPartition {
    [CmdletBinding()]
    param ()

    #Get all Disks
    $GetDisk = $(Get-Disk | Select-Object -Property * | Sort-Object DiskNumber)

    #Must have 1 or more Partitions
    $GetDisk = $GetDisk | Where-Object {$_.NumberOfPartitions -ge '1'}

    #Must be a Fixed Disk
    $GetDisk = $GetDisk | Where-Object {$_.ProvisioningType -eq 'Fixed'}

    #Must be Online
    $GetDisk = $GetDisk | Where-Object {$_.OperationalStatus -eq 'Online'}

    #Must have a Size
    $GetDisk = $GetDisk | Where-Object {$_.Size -gt 0}

    #Must not be Offline
    $GetDisk = $GetDisk | Where-Object {$_.IsOffline -eq $false}

    #TRUE if this disk contains the system partition, or FALSE otherwise
    $GetDisk = $GetDisk | Where-Object {$_.IsSystem -eq $true}

    #Return Results
    Return $GetDisk
}