Skip to content

milejanic/PartitionPilot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PartitionPilot

Interactive PowerShell wizard for Windows disk partitioning. Auto-diagnoses disk state, recognizes the typical scenario, suggests the best plan, and executes it after confirmation — all in the terminal, no GUI.

🇷🇸 Srpska verzija: README.sr.md

Version: 0.1 License: MIT Tested on: Windows 10/11, PowerShell 5.1+


Why this exists

After cloning a smaller disk to a larger one (e.g. 256 GB → 1 TB NVMe), the new drive still has the old partition layout, leaving most of the new space unallocated. Disk Management can do the resize, but it’s clicky and error-prone — and breaks down when the OEM Recovery partition sits right after C: and blocks expansion.

PartitionPilot detects that situation (and a few others), proposes a sensible split, moves the Recovery partition to the end of the disk if needed, and runs everything as a logged, idempotent, dry-runnable script. One file, no install.


Table of Contents

  1. Quick start
  2. What the script does
  3. Recognized scenarios
  4. Menu options
  5. Default split rules
  6. Command-line parameters
  7. Dry-run mode
  8. Moving the Recovery partition (Scenario B)
  9. Log files
  10. Safety mechanisms
  11. Troubleshooting
  12. Typical workflow
  13. Function reference
  14. Roadmap
  15. Contributing
  16. License

Quick start

Easiest — any PowerShell window (even non-admin):

& "C:\path\to\Invoke-PartitionPilot.ps1"

The script will request UAC elevation and re-launch itself as Administrator.

Always dry-run first to see what it would do:

& "C:\path\to\Invoke-PartitionPilot.ps1" -DryRun

Non-interactive (for scripted use):

& "C:\path\to\Invoke-PartitionPilot.ps1" -DiskNumber 0 -SystemSizeGB 500 -DataLetter D -DataLabel "Data" -AutoConfirm

What the script does

Typical use case is right after cloning a smaller disk onto a larger one, but the same flow handles other situations.

Phases:

  1. Pre-flight — checks admin rights; if not elevated, re-launches itself with UAC.
  2. Disk scanGet-Disk filtered to online physical disks (skips virtual / offline).
  3. Disk selection — auto-suggests a candidate (only one disk with significant free space, or the system disk), otherwise asks.
  4. Detailed analysis — partitions with offsets, GPT type GUIDs, free regions classified as start / middle / end of disk, Get-PartitionSupportedSize for the system partition.
  5. Scenario classification — auto-detects A–E (see below).
  6. Proposal + menu — shows the plan, offers a menu of choices.
  7. Plan + confirmation — explicit listing of every step, asks for typed confirmation.
  8. Step-by-step execution — progress messages, error handling, try/catch around every action.
  9. Verification — prints the new layout (partitions + volumes).
  10. Logging — full transcript to a log file for audit.

Recognized scenarios

A) Clone Expand

When: all free space is at the end of the disk, immediately after C: (classic post-clone layout). Heuristic: has C:, has free space at end (>10% of disk), nothing between C: and the end. Plan: resize C: to the suggested size + new data partition in the remainder.

B) Recovery Blocks

When: OEM Recovery partition sits right after C: and prevents expansion (very common on factory Windows installs). Heuristic: Recovery partition with offset within 100 MB of C: end + free space at end of disk. Plan: move Recovery to the end of the disk (standard Microsoft procedure, see below) + resize C: + new data partition.

C) Multi Partition

When: disk already has multiple partitions, but isn’t fully utilized. Plan: create a new partition in the unallocated space (does not touch existing partitions).

D) Empty Disk

When: blank, uninitialized disk (raw NVMe, fresh drive). Plan: GPT initialize + one or more partitions.

E) Other

When: layout doesn’t match any template. Plan: drop into advanced mode for individual operations.


Menu options

After the scenario summary you get:

Option Action
1 Accept proposal (default) — applies the auto-plan
2 Custom split — you enter the system partition size
3 Everything to system — extend C: to maximum, no new partition
4 New partition only — don’t touch C:, just create a partition in free space
5 Advanced — individual operations (resize / new / delete / format / change letter / move recovery)
0 Exit — no changes

Advanced mode (option 5)

Individual operations:

  1. Resize C:
  2. New partition in unallocated space
  3. Delete partition (asks for typed OBRISI confirmation)
  4. Move Recovery to end of disk
  5. Format partition
  6. Change drive letter / label
  7. Show disk again

Default split rules

If you don’t pass -SystemSizeGB, the script proposes based on total disk size:

Total disk size Proposal
≤ 500 GB Everything to the system partition
500 – 1000 GB 50/50 split (system + data)
> 1000 GB 500 GB system + remainder for data

Rules live in Get-SuggestedSplit and are easy to tweak.


Command-line parameters

Parameter Type Default Description
-DiskNumber int -1 (asks) Disk number from Get-Disk
-SystemSizeGB int 0 (auto) System partition size in GB
-DataLetter char D Drive letter for the new partition
-DataLabel string Podaci Volume label
-Scenario string Auto Force A/B/C/D/E
-AutoConfirm switch off Skip interactive confirmations
-DryRun switch off Dry run, change nothing

Examples:

# Interactive (recommended for first run)
.\Invoke-PartitionPilot.ps1

# Automated: disk 0, 500 GB system, no prompts
.\Invoke-PartitionPilot.ps1 -DiskNumber 0 -SystemSizeGB 500 -AutoConfirm

# Force scenario B (move Recovery)
.\Invoke-PartitionPilot.ps1 -DiskNumber 0 -Scenario B -SystemSizeGB 600

# Dry run
.\Invoke-PartitionPilot.ps1 -DryRun

# Different letter/label
.\Invoke-PartitionPilot.ps1 -DataLetter F -DataLabel "Clients"

Dry-run mode

-DryRun simulates execution:

  • All diagnostic commands run normally (read-only).
  • Scenario classification runs.
  • The plan is generated and displayed.
  • Destructive steps print [DRY-RUN] skipping execution instead of running.

Ideal for:

  • First check on a new machine.
  • Demoing or documenting "this is what would happen".
  • Verifying the layout is standard enough that the auto-plan applies.

Moving the Recovery partition (Scenario B)

Delicate operation, used when factory Recovery sits behind C: and blocks resize. Standard Microsoft procedure:

  1. reagentc /info — current WinRE location.
  2. reagentc /disable — exports WinRE.wim to C:\Windows\System32\Recovery\ (safety backup).
  3. Remove-Partition — delete the old Recovery partition behind C:.
  4. Resize-Partition — extend C: to the requested size, leaving 1 GB reserve at end of disk.
  5. New-Partition — create a new partition at the end (1 GB), GPT type Recovery ({de94bba4-06d1-4d40-a16a-bfd50179d6ac}).
  6. Format-Volume — NTFS, label "Recovery".
  7. diskpart gpt attributes=0x8000000000000001 — set GPT attributes (no-drive-letter + platform-required).
  8. reagentc /enable — activate WinRE in the new location (copies WinRE.wim back).

Safety: WinRE.wim stays in C:\Windows\System32\Recovery\ even after activation, so a backup exists if anything goes wrong. If reagentc /enable fails, the system still boots — only Recovery (F8 boot menu) won’t work until repaired.

Reserve size is controlled by $RECOVERY_RESERVE_MB (default 1024 MB = 1 GB). Windows 11 typically wants ~750 MB; 1 GB is a safe ceiling.


Log files

Every run logs to:

C:\ProgramData\PartitionTool\logs\partition_YYYY-MM-DD_HH-mm-ss.log

Each run creates a new log. Format:

=== Partitioning started 2026-05-02_14-30-15 ===
[14:30:15] [INFO] PARTITION WIZARD
[14:30:15] [INFO] Log: C:\ProgramData\PartitionTool\logs\partition_2026-05-02_14-30-15.log
[14:30:18] [INFO] STEP 1/2 Resize C: na 500 GB
[14:30:22] [INFO]   [OK] success
...

Useful for audit when working across multiple machines (clients, colleagues). Logs stay local.


Safety mechanisms

  • Whitelist principle — touches only what's explicitly in the plan, never deletes by schedule.
  • Filters offline / unhealthy disks — ignores anything not OperationalStatus = Online and HealthStatus = Healthy.
  • Skips virtual disksBusType = File Backed Virtual is excluded (Hyper-V VHDX, etc.).
  • DryRun-DryRun blocks all destructive commands, leaves diagnostics in place.
  • Double confirmation for deleteRemove-Partition in advanced mode asks for the typed word OBRISI (not just "yes").
  • Try/catch around every action — failure in one step doesn’t leave the system in an undefined state.
  • Pre-resize validationGet-PartitionSupportedSize is called before requesting a size.
  • WinRE backup before Recovery movereagentc /disable automatically exports WinRE.wim.

Troubleshooting

"Cannot extend C: to X GB"

Cause: something is blocking expansion — usually a Recovery partition behind C:. Fix: if scenario B wasn’t auto-detected, run with -Scenario B.

reagentc /disable returns "is already disabled"

Safe — the script detects that and continues. Means WinRE was already off (often after an in-place Windows upgrade).

Script opens a new window that closes immediately

Cause: UAC elevation opens a new session that doesn’t inherit -NoExit on some systems. Fix: open PowerShell manually as Administrator (right-click → Run as administrator), then run the script there.

"Drive letter D is already in use"

Fix: either run with -DataLetter F (different letter), or first change the letter of the existing D: in advanced mode.

Wrong scenario detected

Fix: force with -Scenario A/B/C/D or use advanced mode (-Scenario E or option 5 from menu).

After a Recovery move F8/WinRE doesn’t work

Fix:

reagentc /info
reagentc /enable

If still broken, WinRE.wim is still in C:\Windows\System32\Recovery\:

reagentc /setreimage /path C:\Windows\System32\Recovery

"Get-PartitionSupportedSize: SizeMax = 0"

Cause: usually means you don't have admin rights, or something is blocking expansion. Fix: run as Administrator.


Typical workflow

Scenario: you just got a new laptop with Windows, cloned the old disk.

  1. Boot from the new disk, confirm Windows works.
  2. Win + X → Windows PowerShell.
  3. Run:
    & "C:\Users\YOU\Downloads\Invoke-PartitionPilot.ps1" -DryRun
  4. Review the plan. Does the scenario match reality?
  5. If yes, run without -DryRun:
    & "C:\Users\YOU\Downloads\Invoke-PartitionPilot.ps1"
  6. UAC → Yes → choose option 1 (accept proposal) or 2 (custom split).
  7. Type da to confirm (will be configurable in v0.2).
  8. Wait — resize takes 30 seconds to a few minutes depending on disk size.
  9. Verification at the end shows the new state. No restart required to access the new partition.
  10. (Optional) Restart to let Windows confirm everything.

Verify later:

Get-Volume | ft DriveLetter, FileSystemLabel, FileSystem, Size, SizeRemaining

Function reference

The script is modular — each function has a clear responsibility.

Function Responsibility
Test-Administrator Admin rights check
Invoke-SelfElevate UAC re-launch with original parameters
Get-DiskOverview List of all relevant disks
Get-FreeRegions Identify unallocated regions (start/middle/end)
Find-RecoveryPartitions All Recovery partitions on a disk
Get-DiskScenario A/B/C/D/E classification with reason
Get-SuggestedSplit Default split rules
Select-Disk Auto-suggest or manual selection
Show-DiskDetails Pretty-printed layout
Move-RecoveryToEnd Move Recovery to end of disk (Scenario B)
Invoke-ResizeC Resize the system partition
Invoke-NewDataPartition Create + format a new partition
Invoke-InitializeDisk GPT init for an empty disk
Build-Plan Generate plan for a given scenario
Show-Plan Display the plan before confirmation
Invoke-Plan Step-by-step execution
Show-Menu / Run-Advanced Interactive menus
Initialize-Log / Write-Log Log infrastructure
Confirm-Yes Standardized confirmation
Invoke-Step Action wrapper with DryRun support
Main Main flow

Roadmap

v0.1 (current):

  • Scenarios A–E with auto-detection.
  • Interactive and parameterized modes.
  • DryRun.
  • Recovery move (Scenario B).
  • Log files.

v0.2 (planned):

  • English-language prompts (currently Serbian).
  • Multi-disk operations (move partition between disks).
  • BitLocker detection — must manage-bde -unlock before resize.
  • Storage Spaces detection — skip pool members.
  • ReFS option for data partitions.

v1.0 (target):

  • PowerShell module form (Install-Module PartitionPilot).
  • Pester test suite.
  • GitHub Actions CI on Windows runners.

v2.0 (longer term):

  • Linux companion (parted/sgdisk).

Contributing

Pull requests welcome. Especially helpful:

  • New scenarios discovered in the wild (please include Get-Partition -DiskNumber X | fl output as anonymized fixture in docs/scenarios/).
  • Bug reports with the log file from C:\ProgramData\PartitionTool\logs\.
  • Translations of prompts.

Before opening a PR, run the script once with -DryRun against a couple of layouts to confirm nothing regresses.


License

MIT — see LICENSE.

No warranty. Always run -DryRun before destructive operations. If something breaks, the log file is in C:\ProgramData\PartitionTool\logs\.


Hit a layout PartitionPilot doesn’t handle? Open an issue with your Get-Partition output — we’ll add it to v0.2.

About

Interactive PowerShell wizard for Windows disk partitioning - auto-detects scenarios, proposes the best plan, executes after confirmation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors