powershell upgrade HD code

cesmith9999

Well-Known Member
Mar 26, 2013
1,160
352
83
I wrote this script to automate upgrading my 1.5 TB disks to 3 TB disks on my storage spaces.

$MissingDisk = $Null
$ReplacementDisk = $null

#Find Missing disk
$MissingDisk = Get-PhysicalDisk | Where-Object { $_.OperationalStatus -eq 'Lost Communication' }
$MissingDisk

#retire Missing disk from storagepool
$MissingDisk | Set-PhysicalDisk -Usage Retired

#find replacement disk - assumes that any free disk will get added to the pool.
while ($ReplacementDisk -eq $null) {
$ReplacementDisk = Get-PhysicalDisk | where {$_.canpool -eq $true}
$ReplacementDisk
if ($ReplacementDisk -eq $null) {sleep -seconds 10}
}

#add the replacement disk(s) to the pool
Add-PhysicalDisk -PhysicalDisks $ReplacementDisk -StoragePoolFriendlyName StoragePool01

#look at the health of the virtual disks
$VDisk = get-virtualdisk | where {$_.OperationalStatus -like "Degraded"}
$VDisk

#rebuild the virtual disks - smallest to largest
foreach ($vd in $VDisk | sort allocatedsize ) {repair-virtualdisk $vd.friendlyname}

#remove the failed disk form the pool - manual confirmation
remove-physicaldisk -PhysicalDisks $MissingDisk -StoragePoolFriendlyName StoragePool01 -confirm:$false


To be honest. I stole some of this code from someone else's webpage. but I definitely made this my own.
 
Last edited:
  • Like
Reactions: Patrick