Deploy-VM

Uit Brakwiki
Versie door Ben (Overleg | bijdragen) op 20 nov 2017 om 02:52 (Nieuwe pagina aangemaakt met '<pre> param ( [string]$VMName, [string]$Drive, [string]$SWName="Brakdom vSwitch", [string]$Description, [switch]$StartVM ) $Imagepath = "D:\Hyper-V\braklnxxx\Virtu...')
(wijz) ← Oudere versie | Huidige versie (wijz) | Nieuwere versie → (wijz)
Ga naar: navigatie, zoeken
param (
[string]$VMName,
[string]$Drive,
[string]$SWName="Brakdom vSwitch",
[string]$Description,
[switch]$StartVM
)

$Imagepath = "D:\Hyper-V\braklnxxx\Virtual Hard Disks\braklnxxx.vhdx"
$VMPath = "$Drive`:\Hyper-V\$VMName"
$VHD = "$Drive`:\Hyper-V\$VMName\Virtual Hard Disks\$VMName.vhdx"

#New-VM -Name Test01 -NewVHDPath "D:\Hyper-V\Test01\Virtual Hard Disks\Test01-c.vhdx" -NewVHDSizeBytes 25GB -SwitchName "Brakdom TestLAN" -Path d:\Hyper-V -MemoryStartupBytes 1GB -Generation 2
if (Get-Item -Path $VMPath -ErrorAction SilentlyContinue) { Write-Host "Folder for VM already exists"; Exit} else { write-host "OK"}
New-VM -Name $VMName -NoVHD -SwitchName $SWName -Path "$Drive`:\Hyper-V" -MemoryStartupBytes 1GB -Generation 1
New-Item -Path "$VMPath\Virtual Hard Disks" -ItemType directory
Set-VM -Name $VMName -DynamicMemory -MemoryMinimumBytes 512MB -MemoryStartupBytes 1GB -MemoryMaximumBytes 1GB -Notes $Description
Copy-Item -Path $Imagepath -Destination $VHD
Add-VMHardDiskDrive -VMName $VMName -Path $VHD -ControllerType IDE
$OsVirtualDrive = Get-VMHardDiskDrive -VMName $VMName -ControllerNumber 0
#Set-VMFirmware -VMName $VMName -FirstBootDevice $OSVirtualDrive
Set-VMBios -VMName $VMName -EnableNumLock -StartupOrder @("IDE", "LegacyNetworkAdapter", "CD", "Floppy")
if ($StartVM) {
    	sleep 10
	Start-VM -Name $VMName
}