-
Notifications
You must be signed in to change notification settings - Fork 0
Hyper‐V Creating New, and Linked VM's
T20A02 edited this page Dec 8, 2023
·
3 revisions
These are the commands used in order top create a new base VM via powershell
$VMName = "BaseVM"
$VMPath = "C:\Hyper-V\VMs"
$ISOPath = "C:\Path\to\WindowsServer2019.iso"
New-VM -Name $VMName -Path $VMPath -MemoryStartupBytes 4GB -NewVHDPath "$VMPath\$VMName.vhdx" -NewVHDSizeBytes 60GB
Set-VMBios -VMName $VMName -BootOrder "CD"
Add-VMDvdDrive -VMName $VMName -Path $ISOPath
Start-VM -Name $VMNameThese are the commands used in order, to make a linked clone of a VM
$LinkedVMName = "LinkedCloneVM"
New-VHD -Path "C:\Hyper-V\VMs\$LinkedVMName.vhdx" -ParentPath "C:\Hyper-V\VMs\BaseVM.vhdx" -Differencing
New-VM -Name $LinkedVMName -Path "C:\Hyper-V\VMs" -MemoryStartupBytes 4GB -VHDPath "C:\Hyper-V\VMs\$LinkedVMName.vhdx"
Start-VM -Name $LinkedVMNameTo stop a virtual machine using PowerShell, you can execute the following command:
Stop-Service -Name YourVMName
# OR
Stop-Process -Name YourVMName
Checkpoint-VM -Name YourVMName -SnapshotName snapshot1
# OR
Checkpoint-Computer -Name YourVMName -SnapshotName snapshot1
Start-Service -Name YourVMName
# OR
Start-Process -Name YourVMName
# Change the network profile for 'YourVMName' to another network by name
Set-NetConnectionProfile -InterfaceAlias YourVMName -NetworkCategory "Private"
# OR
# Change the IP address of 'YourVMName' to another network
Set-NetIPAddress -InterfaceAlias YourVMName -IPAddress NewIPAddress -PrefixLength SubnetMask -DefaultGateway NewGateway
Written in part with ChatGPT