How about this?
$MainDisk = 0
ForEach ($disk in (Get-PhysicalDisk | Select-Object DeviceID, MediaType, Size)){
If ($disk.MediaType -eq 'SSD' -and $disk.Size -gt 100GB){
$MainDisk = $disk.DeviceID
break
}
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm trying to create a PowerShell script to check if any of the computer's disks is an SSD and then pass that disk number as a variable to other scripts, which will use it to select which disk a Windows image will be installed to. Also, the SSD must be larger than a certain size, otherwise the script may select my UFD boot media. I'm still new to scripting in PS, so I'm having difficulty getting this to work (though I think I'm on the right track). Note that this script needs to run in PowerShell within WinPE.
Here's my pseudo code script:
$disks = Get-PhysicalDisk | Select DeviceID, MediaType, Size
If number of disks > 1 Then
For Each disk
If MediaType = SSD AND Size > 100GB Then
$mainDisk = DeviceID
Exit Loop
Else
End If
Next disk
Else
End If
If $mainDisk is $null Then
$mainDisk = disk 0
Else
End If
Pass $mainDisk to script for disk config/Windows install
(Please excuse the lack of proper PS syntax as I figure it would be easier to understand this way due to my limited familiarity with PS syntax)
The key here is the Get-PhysicalDisk Cmdlet. I think a big part of my problem is that the $disks variable is created as a PSCustomObject as opposed to a Hashtable and I can't seem to get the rest of my script to work with it.
If anyone has a better approach, I'd love to hear it.
Any help would be greatly appreciated. Thanks in advance.
How about this?
$MainDisk = 0
ForEach ($disk in (Get-PhysicalDisk | Select-Object DeviceID, MediaType, Size)){
If ($disk.MediaType -eq 'SSD' -and $disk.Size -gt 100GB){
$MainDisk = $disk.DeviceID
break
}
}