Update Invoke-OperatingSystemDiskDetection.ps1

This commit is contained in:
freedbygrace
2023-10-17 11:38:15 -04:00
committed by GitHub
parent 82cd8a7681
commit 3a401df7fb
+18 -4
View File
@@ -1,4 +1,4 @@
<#
<#
.SYNOPSIS
Dynamically determines the desired operating system disk based on a calculated MediaType and BusType priority.
@@ -10,6 +10,9 @@
.PARAMETER BusTypeExclusionExpression
A valid regular expression to exclude disks for from consideration based on their bus type. By default, USB based disks will be excluded.
.PARAMETER DiskSizeThresholdInGB
Grants the ability to filter out disks that are smaller than the specified value in gigabytes. This is useful for situations where an Intel Optane Memory Cache might be present.
.NOTES
By default, the operating system will get deployed onto the fatest and smallest disk.
@@ -30,7 +33,7 @@
[Parameter(Mandatory=$False)]
[ValidateNotNullOrEmpty()]
[Alias('DST')]
[UInt32]$DiskSizeThresholdInGB = 32
[UInt64]$DiskSizeThresholdInGB = 1024
)
Try
@@ -205,14 +208,25 @@ Try
$DiskPropertyList.Add('BusType')
$DiskPropertyList.Add(@{Name = 'BusTypePriority'; Expression = ($DetermineBusTypePriority)})
$DiskPropertyList.Add(@{Name = 'SizeInGB'; Expression = {[System.Math]::Round(($_.Size / 1GB), 2)}})
$DiskPropertyList.Add(@{Name = 'SizeInBytes'; Expression = {$_.Size}})
$OutputObjectProperties.DiskList = Get-PhysicalDisk | Where-Object {($_.BusType -inotmatch $BusTypeExclusionExpression) -and ($_.Size -gt ($DiskSizeThresholdInGB / 1GB))} | Sort-Object -Property @('Size') | Select-Object -Property ($DiskPropertyList)
$LoggingDetails.LogMessage = "$($GetCurrentDateTimeMessageFormat.Invoke()) - Attempting to search for any disk(s) matching the specified criteria. Please Wait..."
Write-Verbose -Message ($LoggingDetails.LogMessage) -Verbose
[UInt64]$DiskSizeThresholdInBytes = $DiskSizeThresholdInGB * 1GB
[ScriptBlock]$DiskListerCriteria = {($_.BusType -inotmatch $BusTypeExclusionExpression) -and ($_.Size -gt $DiskSizeThresholdInBytes)}
$LoggingDetails.LogMessage = "$($GetCurrentDateTimeMessageFormat.Invoke()) - Disk List Criteria: $($DiskListerCriteria)"
Write-Verbose -Message ($LoggingDetails.LogMessage) -Verbose
$OutputObjectProperties.DiskList = Get-PhysicalDisk | Where-Object -FilterScript ($DiskListerCriteria) | Sort-Object -Property @('Size') | Select-Object -Property ($DiskPropertyList)
$OutputObjectProperties.DiskListCount = ($OutputObjectProperties.DiskList | Measure-Object).Count
$OutputObjectProperties.DesiredOperatingSystemDisk = $Null
$OutputObjectProperties.DesiredOperatingSystemDiskLocated = $False
$OutputObjectProperties.IsTaskSequenceRunning = $IsRunningTaskSequence
$LoggingDetails.LogMessage = "$($GetCurrentDateTimeMessageFormat.Invoke()) - Detected $($OutputObjectProperties.DiskListCount) physical disk(s)."
$LoggingDetails.LogMessage = "$($GetCurrentDateTimeMessageFormat.Invoke()) - Detected $($OutputObjectProperties.DiskListCount) disk(s) meeting the specified criteria."
Write-Verbose -Message ($LoggingDetails.LogMessage) -Verbose
Switch ($OutputObjectProperties.DiskListCount -gt 0)