Functions/New-HyperVImage.ps1
function New-HyperVImage { [CmdletBinding()] param ( [parameter(mandatory=$true)]$VMName, [parameter(mandatory=$true)]$Path, [parameter(mandatory=$true)]$IsoFile, [Parameter(Mandatory=$true)][string]$vSwitch, [switch]$StartVM, [switch]$Connect ) New-VM -Name $VMName -SwitchName $vSwitch -Generation 2 -MemoryStartupBytes 4Gb -Path $Path -NewVHDPath "$($VMName).vhdx" -NewVHDSizeBytes 40GB Set-VMProcessor $VMName -Count 2 Set-VMMemory $VMName -DynamicMemoryEnabled $false if($IsoFile) { Add-VMDvdDrive -VMName $VMName -Path $IsoFile } $vmDvdDrive = Get-VMDvdDrive $VMName Set-VMFirmware $VMName -FirstBootDevice $vmDvdDrive Enable-VMIntegrationService -VMName $VMName -Name "Guest Service Interface" Set-VMKeyProtector $VMName -NewLocalKeyProtector Enable-VMTPM $VMName Set-VM $VMName -AutomaticStartAction Nothing -AutomaticStopAction ShutDown -CheckpointType Disabled Set-VMVideo -VMName $VMName -ResolutionType Single -HorizontalResolution 1440 -VerticalResolution 900 if($Connect) { vmconnect.exe Zolder $VMName } if($StartVM) { Start-VM $VMName } Get-VM $VMName } #Export-ModuleMember -Function New-HyperVImage |