Automating diskpart commands using PowerShell

A small script to generate a ASCII text file to automate diskpart. Using this with PSExec can make a quick yet powerful tool.

This script in particular automates the process of rescanning a disk and extending the select volume in Windows Server 2008 or Windows 7.

$script = $Null
$script = @"
rescan 
select disk 0
select volume 2
extend
exit
"@
$script | Out-File -Encoding ASCII -FilePath "c:\Diskpart-extend.txt"

diskpart.exe /s c:\Diskpart-extend.txt

Leave a Reply