This is a quick post about some tools I used during previous project of deploying server core for an online gambling firm I worked for. We often found ourselves expanding disk and wanted to automate the process by including logging in to the OS and extending after VMware vmdk expansion.
###Expand VM Hard Disk Using dispart.txt on windows 2012r2
#download pstools from https://docs.microsoft.com/en-us/sysinternals/downloads/psexec and open zip and copy PsExec.exe & PsExec64 to scripts folder
#create diskpart.txt in scripts folder and include below
#Run powercli as domain admin account
# Path into script folder and save below as PS.1
$vCenter=”uk3p-vc01.lab.local”
$NewSizeGB=108
$vms=("Ron-Test01")
connect-viserver $vCenter
foreach ($vm in $vms) {
get-vm $vm | get-harddisk | where {$_.name -eq “Hard Disk 1”} | set-harddisk -confirm:$false -capacityGB $NewSizeGB
copy diskpart.txt \\$vm\c$\windows\temp\
.\PsExec.exe \\$vm diskpart /s C:\windows\temp\diskpart.txt
}
disconnect-viserver -Confirm:$false
diskpart.txt: # create diskpart.txt in scripts folder and include below
rescan
select volume 2
extend
## You can also use this one liner
Get-HardDisk -vm $vms | Where {$_.Name -eq "Hard disk 1"} | Set-HardDisk -CapacityGB 108 -ResizeGuestPartition -Confirm:$false
###Expand VM Hard Disk Using dispart.txt on windows 2012r2
#download pstools from https://docs.microsoft.com/en-us/sysinternals/downloads/psexec and open zip and copy PsExec.exe & PsExec64 to scripts folder
#create diskpart.txt in scripts folder and include below
#Run powercli as domain admin account
# Path into script folder and save below as PS.1
$vCenter=”uk3p-vc01.lab.local”
$NewSizeGB=108
$vms=("Ron-Test01")
connect-viserver $vCenter
foreach ($vm in $vms) {
get-vm $vm | get-harddisk | where {$_.name -eq “Hard Disk 1”} | set-harddisk -confirm:$false -capacityGB $NewSizeGB
copy diskpart.txt \\$vm\c$\windows\temp\
.\PsExec.exe \\$vm diskpart /s C:\windows\temp\diskpart.txt
}
disconnect-viserver -Confirm:$false
diskpart.txt: # create diskpart.txt in scripts folder and include below
rescan
select volume 2
extend