In this post I’ll go over the process of building both Linux and Windows VMs in Oracle VirtualBox using PowerShell on a Windows host.
Prerequisites
- Oracle VirtualBox – I’m currently using version 6.1.40
- Installation media for the target OS – Examples here are with Ubuntu 20.04 (the Server image, not the Desktop one) and with Windows Server 2019 Evaluation
- Sufficient drive space
- Keep in mind that parts of the following commands (paths to ISO files, VM directory paths, and network card name) will need to be updated to match your scenario.
Building Windows VM
Open PowerShell and, to make things easier, append VirtualBox’s installation directory to the PATH environment variable.
1 |
$Env:Path += ";C:\Program Files\Oracle\VirtualBox\" |
Find the OS ID for Windows Server 2019.
1 |
VBoxManage list ostypes | Select-String -Pattern "Windows" | Select-String -Pattern "2019" -Raw |

Create and register an empty Windows Server 2019 VM.
1 |
VBoxManage createvm --name WinSrv2k19 --ostype Windows2019_64 --register |
Take note of the location of the VM’s settings file’s location since that directory will also be the home of the virtual disk file(s).

Add CPU cores, RAM, and VRAM. Set the graphics controller, and set the network type as bridged as well specifying the name of the host’s NIC that will be used.
1 |
VBoxManage modifyvm WinSrv2k19 --cpus 4 --memory 8192 --vram 128 --graphicscontroller vboxsvga --nic1 bridged --bridgeadapter1 "Intel(R) Ethernet Controller I225-V" |
Add a SATA storage controller, specify the controller’s chipset, the port count, and set it as boot-able.
1 |
VBoxManage storagectl WinSrv2k19 --name "SATA" --add sata --controller IntelAHCI --portcount 3 --bootable on |
Create the virtual disk file that will eventually become the C drive.
1 |
VBoxManage createhd --filename F:\VirtualBoxVMs\WinSrv2k19\WinSrv2k19.vdi --size 81920 --variant Standard |
Add a second virtual disk file (optional).
1 |
VBoxManage createhd --filename F:\VirtualBoxVMs\WinSrv2k19\WinSrv2k19_1.vdi --size 40960 --variant Standard |
Attach the two disks to the storage controller.
1 |
VBoxManage storageattach WinSrv2k19 --storagectl "SATA" --port 0 --device 0 --type hdd --medium F:\VirtualBoxVMs\WinSrv2k19\WinSrv2k19.vdi |
1 |
VBoxManage storageattach WinSrv2k19 --storagectl "SATA" --port 1 --device 0 --type hdd --medium F:\VirtualBoxVMs\WinSrv2k19\WinSrv2k19_1.vdi |
Attach the Windows Server 2019 Evaluation ISO.
1 |
VBoxManage storageattach WinSrv2k19 --storagectl "SATA" --port 2 --device 0 --type dvddrive --medium C:\Users\Vlad\Downloads\WinSRV2019_latest_release_svc_refresh_SERVER_EVAL_x64FRE_en-us_1.iso |
Start the VM.
1 |
VBoxManage startvm WinSrv2k19 |
And proceed with the OS install process as described here.
Building an Ubuntu VM
Open PowerShell and, to make things easier, append VirtualBox’s installation directory to the PATH environment variable.
1 |
$Env:Path += ";C:\Program Files\Oracle\VirtualBox\" |
Find the OS ID for Ubuntu 64bit.
1 |
VBoxManage list ostypes | Select-String -Pattern "ubuntu" -Raw |

Create and register an empty Ubuntu 64bit VM.
1 |
VBoxManage createvm --name Ubuntu --ostype Ubuntu_64 --register |
Take note of the location of the VM’s settings file’s location since that directory will also be the home of the virtual disk file(s).

Add CPU cores, RAM, and VRAM. Set the graphics controller, and set the network type as bridged as well specifying the name of the host’s NIC that will be used.
1 |
VBoxManage modifyvm Ubuntu --cpus 4 --memory 8192 --vram 16 --graphicscontroller vmsvga --nic1 bridged --bridgeadapter1 "Intel(R) Ethernet Controller I225-V" |
Add a SATA storage controller, specify the controller’s chipset, the port count, and set it as boot-able.
1 |
VBoxManage storagectl Ubuntu --name "SATA" --add sata --controller IntelAHCI --portcount 1 --bootable on |
Add an IDE storage controller, for CD/DVD images.
1 |
VBoxManage storagectl Ubuntu --name "IDE" --add ide --controller PIIX4 --hostiocache on |
Create the virtual disk file.
1 |
VBoxManage createhd --filename F:\VirtualBoxVMs\Ubuntu\Ubuntu.vdi --size 40960 --variant Standard |
Attach the virtual disk file to the SATA storage controller.
1 |
VBoxManage storageattach Ubuntu --storagectl "SATA" --port 0 --device 0 --type hdd --medium F:\VirtualBoxVMs\Ubuntu\Ubuntu.vdi |
Attach the ISO to the IDE controller.
1 |
VBoxManage storageattach Ubuntu --storagectl "IDE" --port 0 --device 0 --type dvddrive --medium C:\Users\Vlad\Downloads\ubuntu-20.04.5-live-server-amd64.iso |
Start the VM.
1 |
VBoxManage startvm Ubuntu |
And proceed with the OS install process as described here.
Conclusion
While building VMs from PowerShell might seem intimidating if you’re not used with the command line, the process isn’t really that intricate and can end up saving you a lot of time if you tear down and build new VMs fairly often.
If you’re curios about the Windows Terminal theme that makes the above screenshots so easy to read: it’s called Retrowave, by Chrissy LeMaire, and you can find it here.
Leave a Reply