PowerShell

My Home Hyper-v Script

$VMName = Read-Host -Prompt ‘Input your VM name-No space or special char’

# Create one vm 2GB Ram and a Bootdisk 50GB 
$VM = @{
Name = $VMName
MemoryStartupBytes = 2147483648
Generation = 2
NewVHDPath =C:\Users\Public\Documents\Hyper-V\Virtual  Hard Disks\$VMName.vhdx”
NewVHDSizeBytes = 53687091200
BootDevice = “VHD”
Path = “C:\Virtual Machines\$VMName
SwitchName = (Get-VMSwitch).Name[0]
}

New-VM @VM
Start-VM $VMName
Get-VM | where {$_.State -eq ‘Running’}
# Get-VM | where {$_.Name -like ‘win*’}