Short scripts - usually bash or something else Linux-y
These are some PowerShell snippets that I use to create and manage VMs. I am very new to PowerShell…like my first day using it…ever. These are more notes for me to remember important commands.
For all examples, assume a VM with the name of dev-vm
.
First things first – the VM needs to be created:
PS C:\> New-VM -Name dev-vm -MemoryStartupBytes 1GB -NewVHDPath "test-vm.vhdx" -NewVHDSizeBytes 12GB -SwitchName Intnet
More CPU Power! (Only one CPU core by default):
PS C:\> Set-VMProcessor dev-vm -count 2
Remove all Network Adapters:
PS C:\> Remove-VMNetworkAdapter -VMName dev-vm
Add a Legacy Network Adapter, useful for PXE booting. The name of the network that boots from my internal deployment server is Intnet
. Your switch name will vary:
PS C:\> Add-VMNetworkAdapter -VMName dev-vm -IsLegacy $true -SwitchName Intnet
Add a Network Adapter, done after a PXE install is completed or not required. Your SwitchName will likely vary here as well:
PS C:\> Add-VMNetworkAdapter -VMName dev-vm -SwitchName External-Wired
Power on a VM:
PS C:\> Start-VM –Name dev-vm
Gracefully shutdown a VM.
PS C:\> Stop-VM –Name dev-vm
Give the VM five minutes to shutdown, and then do a hard power off.
PS C:\> Stop-VM -Force –Name dev-vm
Do a hard power off.
PS C:\> Stop-VM -TurnOff –Name dev-vm