probably an easy one but i’m trying to make a script to run some diskpart commands but not having much luck (keeps timing out). specifically i added disk space but Windows has a 500mb recovery partition that i need to delete first). i can manually take care of it w/ disk part by running: diskpart, select disk 0 , select partition 2, delete partition override, select partition 1, extend
This is what I use to extend the drives with a recovery partition. https://www.reddit.com/r/sysadmin/comments/qbggff/comment/imj0sc9/
thanks! so have you put this all in a script and had it work?
Haven’t tried it in a script, just use it in my lab.
and if you run the reagentc /disable command first, if you then go into diskpart can you just use the delete partition override right away or i assume you need to manually select the correct recovery volume first right so it knows which one?
You would need to select partition X and then do a delete partition.
ok cool so the only difference i guess is to make sure to run the reagentc commands to make sure it doesnt break stuff
I’ve slept since but I seem to remember not being able to delete the partition otherwise. You had to use 3rd party partitioning tools to move the volume.
cool ya i’ve been able to easily just go right into diskpart and run the commands i listed above and then extend w/out an issue for what its worth. i just can’t get it to work in controlup for some reason. manually running it works fine
alright i found what i was doing wrong and this ended up working. thanks for the help!“`reagentc /disable
(echo Rescan
echo list disk
echo select disk 0
echo list volume
echo select volume 2
echo delete partition override
echo list volume
echo select volume 1
echo extend
) | diskpart
reagentc /enable
exit“`You can also do this with powershell @member
“`# Import the Storage module
Import-Module Storage
Run DiskPart commands
$diskNumber = 0
$volumeNumber1 = 1
$volumeNumber2 = 2
Rescan disks
Update-HostStorageCache
List disks
Get-PhysicalDisk
Select disk
$disk = Get-PhysicalDisk -DeviceID $diskNumber
$disk | Select-Object -Property *
List volumes
Get-Volume
Select volume
$volume = Get-Volume -PartitionStyle GPT | Where-Object { $_.UniqueId -eq $volumeNumber2 }
$volume | Select-Object -Property *
Delete partition
Remove-Partition -DiskNumber $diskNumber -PartitionNumber $volume.PartitionNumber -Confirm:$false
List volumes
Get-Volume
Select volume
$volume = Get-Volume -PartitionStyle GPT | Where-Object { $_.UniqueId -eq $volumeNumber1 }
$volume | Select-Object -Property *
Extend volume
Resize-Partition -DriveLetter $volume.DriveLetter -Size $volume.Size
Enable diskpart-like confirmation output
Set-Partition -DiskNumber $diskNumber -PartitionNumber $volume.PartitionNumber -NewDriveLetter $volume.DriveLetter
Enable Windows Recovery Environment (RE)
reagentc /enable
Exit the script
exit“`
According to Chat-GPT 😉Very nice! Thank you! I’ll give that a try too
Continue reading and comment on the thread ‘How to script diskpart for partition management in ControlUp without timeouts?’. Not a member? Join Here!
Categories: All Archives, ControlUp Scripts & Triggers