In the same way I did for the data disk preparation in the Windows team I had to find a way to extend automatically the system disk (C drive). In order to ease this task I googled and found a solution that I setup my way in DOS but also in PowerShell. Unfortunately it is not possible to perform a live disk extension on Windows 2003 so this script is only working for Windows 2008 and later versions.
This script has to be used once the free space has been delivered on the system partition.
The script is pretty simple :
- Directory preparation "c_disk_ext" in the directory c:\temp
- Creation of a file "c_disk_ext.txt" in the directory "c_disk_ext" and writing in it all the needed commands for the extension.
- Finally it launches DISKPART with the "c_disk_ext.txt" file as parameter
In DOS :
mkdir c:\temp\c_disk_ext
cd c:\temp\c_disk_ext
echo rescan > c_disk_ext.txt
echo select volume c >> c_disk_ext.txt
echo extend >> c_disk_ext.txt
diskpart /s c:\temp\diskpart.txt
In Powershell :
The Powershell console needs to be launched As Administrator and then you can copy and paste this in your console or then you create a PS1 file with this content.
NEW-ITEM -name c_disk_ext -itemtype directory -force
cd c:\temp\c_disk_ext
NEW-ITEM –name c_disk_ext.txt –itemtype file –force | OUT-NULL
ADD-CONTENT –path c_disk_ext.txt “rescan”
ADD-CONTENT –path c_disk_ext.txt “select volume c”
ADD-CONTENT –path c_disk_ext.txt “extend”
diskpart /s c:\temp\c_disk_ext\c_disk_ext.txt