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+
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.
- Quick start
- What the script does
- Recognized scenarios
- Menu options
- Default split rules
- Command-line parameters
- Dry-run mode
- Moving the Recovery partition (Scenario B)
- Log files
- Safety mechanisms
- Troubleshooting
- Typical workflow
- Function reference
- Roadmap
- Contributing
- License
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" -DryRunNon-interactive (for scripted use):
& "C:\path\to\Invoke-PartitionPilot.ps1" -DiskNumber 0 -SystemSizeGB 500 -DataLetter D -DataLabel "Data" -AutoConfirmTypical use case is right after cloning a smaller disk onto a larger one, but the same flow handles other situations.
Phases:
- Pre-flight — checks admin rights; if not elevated, re-launches itself with UAC.
- Disk scan —
Get-Diskfiltered to online physical disks (skips virtual / offline). - Disk selection — auto-suggests a candidate (only one disk with significant free space, or the system disk), otherwise asks.
- Detailed analysis — partitions with offsets, GPT type GUIDs, free regions classified as start / middle / end of disk,
Get-PartitionSupportedSizefor the system partition. - Scenario classification — auto-detects A–E (see below).
- Proposal + menu — shows the plan, offers a menu of choices.
- Plan + confirmation — explicit listing of every step, asks for typed confirmation.
- Step-by-step execution — progress messages, error handling, try/catch around every action.
- Verification — prints the new layout (partitions + volumes).
- Logging — full transcript to a log file for audit.
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.
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.
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).
When: blank, uninitialized disk (raw NVMe, fresh drive). Plan: GPT initialize + one or more partitions.
When: layout doesn’t match any template. Plan: drop into advanced mode for individual operations.
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 |
Individual operations:
- Resize
C: - New partition in unallocated space
- Delete partition (asks for typed
OBRISIconfirmation) - Move Recovery to end of disk
- Format partition
- Change drive letter / label
- Show disk again
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.
| 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"-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 executioninstead 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.
Delicate operation, used when factory Recovery sits behind C: and blocks resize. Standard Microsoft procedure:
reagentc /info— current WinRE location.reagentc /disable— exportsWinRE.wimtoC:\Windows\System32\Recovery\(safety backup).Remove-Partition— delete the old Recovery partition behindC:.Resize-Partition— extendC:to the requested size, leaving 1 GB reserve at end of disk.New-Partition— create a new partition at the end (1 GB), GPT type Recovery ({de94bba4-06d1-4d40-a16a-bfd50179d6ac}).Format-Volume— NTFS, label "Recovery".diskpart gpt attributes=0x8000000000000001— set GPT attributes (no-drive-letter + platform-required).reagentc /enable— activate WinRE in the new location (copiesWinRE.wimback).
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.
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.
- Whitelist principle — touches only what's explicitly in the plan, never deletes by schedule.
- Filters offline / unhealthy disks — ignores anything not
OperationalStatus = OnlineandHealthStatus = Healthy. - Skips virtual disks —
BusType = File Backed Virtualis excluded (Hyper-V VHDX, etc.). - DryRun —
-DryRunblocks all destructive commands, leaves diagnostics in place. - Double confirmation for delete —
Remove-Partitionin advanced mode asks for the typed wordOBRISI(not just "yes"). - Try/catch around every action — failure in one step doesn’t leave the system in an undefined state.
- Pre-resize validation —
Get-PartitionSupportedSizeis called before requesting a size. - WinRE backup before Recovery move —
reagentc /disableautomatically exportsWinRE.wim.
Cause: something is blocking expansion — usually a Recovery partition behind C:.
Fix: if scenario B wasn’t auto-detected, run with -Scenario B.
Safe — the script detects that and continues. Means WinRE was already off (often after an in-place Windows upgrade).
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.
Fix: either run with -DataLetter F (different letter), or first change the letter of the existing D: in advanced mode.
Fix: force with -Scenario A/B/C/D or use advanced mode (-Scenario E or option 5 from menu).
Fix:
reagentc /info
reagentc /enableIf still broken, WinRE.wim is still in C:\Windows\System32\Recovery\:
reagentc /setreimage /path C:\Windows\System32\RecoveryCause: usually means you don't have admin rights, or something is blocking expansion. Fix: run as Administrator.
Scenario: you just got a new laptop with Windows, cloned the old disk.
- Boot from the new disk, confirm Windows works.
Win + X→ Windows PowerShell.- Run:
& "C:\Users\YOU\Downloads\Invoke-PartitionPilot.ps1" -DryRun
- Review the plan. Does the scenario match reality?
- If yes, run without
-DryRun:& "C:\Users\YOU\Downloads\Invoke-PartitionPilot.ps1"
- UAC → Yes → choose option 1 (accept proposal) or 2 (custom split).
- Type
dato confirm (will be configurable in v0.2). - Wait — resize takes 30 seconds to a few minutes depending on disk size.
- Verification at the end shows the new state. No restart required to access the new partition.
- (Optional) Restart to let Windows confirm everything.
Verify later:
Get-Volume | ft DriveLetter, FileSystemLabel, FileSystem, Size, SizeRemainingThe 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 |
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 -unlockbefore 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).
Pull requests welcome. Especially helpful:
- New scenarios discovered in the wild (please include
Get-Partition -DiskNumber X | floutput as anonymized fixture indocs/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.
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.