• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
ControlUp Community

ControlUp Community

Connect, Learn, and Grow

  • Blog
  • Podcast
  • Meetups
  • Archives
  • Categories
    • ControlUp One Platform
    • ControlUp for Apps
    • ControlUp for Compliance
    • ControlUp for Desktops
    • ControlUp Scripts & Triggers
    • ControlUp Synthetic Monitoring
    • ControlUp for VDI
  • Topics
  • Events
    • Logos & Wallpaper
    • ControlUp.com
  • Join

How to script diskpart for partition management in ControlUp without timeouts?

Posted on May 9, 2023

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
Topics: Microsoft Windows, PowerShell, Scripts, Storage

Ask Us Anything, Connect, Learn, and Grow with the ControlUp Community!

Login to the ControlUp Community to ask us anything, stay up-to-date on what’s new and coming soon and meet other like-minded techies like you.

Not already a member? Join Today!

Primary Sidebar

ControlUp Academy

Enroll in ControlUp Academy for expert-led technical training, equipping you with skills to effectively deploy, manage, and grow your ControlUp investment.

Learn here >

Rotating Images

Hidden Gem from our Community on Slack!

ControlUp Betas - What's Coming Next?
NEW ControlUp Features - Stay Up-to-Date!
ControlUp Scripts - Scripting, Zero to Hero
Latest KB Articles - Be the First to Learn
Did you Know - with Sivan Kroitoru
Practical Perspectives Technical Use Case Training

Video Tutorials Library

Visit our technical how-to videos, offering step-by-step tutorials on advanced features, troubleshooting, and best practices.

Watch here >

ControlUp Blog

Check out the ControlUp blog for expert advice and in-depth analysis.

Read here >

ControlUp Script Library

Visit the ControlUp technical script library, which offers a multitude of pre-built scripts and custom actions for your monitoring and troubleshooting requirements.

See here >

ControlUp Support

Visit the ControlUp support home and to delve deeper into ControlUp solutions.

Browse here >

Download ControlUp RealTime DX

Start with ControlUp for real-time end-user environment insights, swift troubleshooting, and unprecedented performance optimization. Download now.

Download here >

Footer

      

ControlUp Community
Of Techie, By Techie, For Techie!

Terms of Use | Privacy Policy | Security
Dive Deeper, Learn more at ControlUp.com

  • facebook
  • twitter
  • youtube
  • linkedin

© 2023–2025 ControlUp Technologies LTD, All Rights Reserved.

We use cookies to ensure that we give you the best experience on our website. by continuing to use this site you agree to our Cookie policy..