System requirements for Hyper-V on Windows Server 2016

Install-WindowsFeature

install VMware tools on Core Windows
setup64.exe /S /v "/qn REBOOT=y"

New-NetlPAddress -interfacealias ethernet0 -IPAddress 192.168.3.200 -Prefixlength 24 -defaultgateway 192.168.3.2
Set-DNSClientServerAddress -interfacealias ethernet0 -ServerAddress 192.168.3.10
New-NetFirewallRule -displayname "Allow All Traffic" -direction outbound -action allow
New-NetFirewallRule -displayname "Allow All Traffic" -direction inbound -action allow
Add-Computer -newname hypervl -domainname <domain> -restart
install-windowsFeature -ComputerName hypervl -Name hyper-v
install-windowsfeature -computername hypervl -name rsat-hyper-v-tools
install-windowsfeature -computername hypervl -name hyper-v-powershell
Get-windowsOptionalFeature -online where featurename -like "*hyper*"
New-VM -ComputerName hypervl -Name VM1 -Generation 2 -MemorystartupBytes 2GB -NewVHDPath vml.vhdx -NewVHDSizeBytes 60000000000 -SwitchName external
start-vm -ComputerName hypervl -Name vml
get-vm -ComputerName hypervl


Configure VMs with PowerShell Direct
- PowerShell Direct offers a new way of running PowerShell commands inside a VM from the host operating system.
- There are no network or firewall requirements or configurations
- PowerShell Direct works regardless of Remote Management configuration
- Guest credentials are required and VM must be running on the host
- Some PowerShell tools not yet available in PowerShell Direct

PowerShell Direct – Running PowerShell inside a virtual machine from the Hyper-V host

3 ways of using PowerShell direct
- Interactive session - Enter-PSSession-VMName VMName
- Single-use session - Invoke-Command-VMName VMName-ScriptBlock { Commands }
- Persistent session - $session = New-PSSession -VMName nanoserverl -Credential (Get-Credential)

copy-item -Fromsession $session -Path c:\nanoserverl.txt -Destination c:\
new-vm -ComputerName hypervl -name VM2 -Version 7.0

Generation 2 Virtual Machine Overview
Upgrade virtual machine version in Hyper-V on Windows 10 or Windows Server 2016

Generation 2 Guest Support
- Windows Server 2016, 2012 R2 & 2012
- Windows 10 x64, Windows 8.1 x64 & Windows 8 x64

Linux Support in Hyper-V
OS Version Gen 1 Gen 2
RHEL/CentOS 7.x series x x
RHEL/CentOS 6.x series x  
RHEL/CentOS 5.x series x  
Debian 7.x series x  
Debian 8.x series x x
FreeBSD 10 and 10.1 x  
FreeBSD 9.1 and 9.3 x  
FreeBSD 8.4 x  
Oracle Linux 7.x series x x
Oracle Linux 6.x series x  
Oracle Linux UEK R3 QU3 x  
Oracle Linux UEK R3 QU2 x  
Oracle Linux UEK R3 QUI x  
SUSE Linux Enterprise Server 12 series x x
SUSE Linux Enterprise Server 11 series x  
Open SUSE 12.3 x  
Ubuntu 14.04 and later versions x x
Ubuntu 12.04 x  

Azman.msc - deprecated GUI tool
JEA - Just enough Administration

Delegation of rights to an AD group
Enter-PSSession hypervl
New-PSRoleCapabilityFile -Path ./rebootonly.psrc
## edit psrc file in ISE & Find section VisibleCmdlets
VisibleCmdlets = 'Restart-VM', 'Get-VM'
## copy psrc file c:\Program Files > WindowsPowerShell > Modules > RebootOnly
## where that can be any folder name, underneatch create folder RoleCapabilities << psrc goes here!
New-PSSessionConfigurationFile -Path ./rebootonly.pssc -full
## edit pssc in ISE and find SessionType
SessionType - "RestrictedRernoteServer"
RunAsVirtualAccount = $true  ## << uncomment this line
## Amend RoleDefinitions
RoleDefinitions =  @{ 'COMPANY\Reboot0nly' = @{ RoleCapabi1ities - 'RebootOnly' } }
Register-PSSessionConfiguration -Name "RebootOnly" -Path .\rebootonly.pssc
## ^this will kick you out^
Enter-PSSession hypervl
Get-PSSessionConfiguration
Enter-PSSession hypervl -ConfigurationName "RebootOnly" -Credential "company\user"
get-command


Supported Boot methods Gen 1 Gen 2
PXE boot by using a standard network adapter   x
PXE boot by using a legacy network adapter x  
Boot from a SCSI VHDX or virtual DVD ISO   x
Boot from IDE Controller VHD or virtual DVD ISO x  
Boot from virtual floppy VFD x  
PXE boot by using a standard network adapter   x
PXE boot by using a legacy network adapter x  
Boot from a SCSI VHDX or virtual DVD ISO   x
Boot from IDE Controller VHD or virtual DVD ISO x  
Boot from virtual floppy VFD x  

Nested Virtualisation
- Host running Windows Server 2016 Windows 10 Anniversary Update
- VM running Windows Server 2016 Windows 10 Anniversary Update
- VM at configuration version 8.0 or greater
- Intel processor with VT-x and EPT

Set-VMProcessor -VMName nanoserverl -ExposeVirtualizationExtensions $true
Get-VMNetworkAdapter -VMName nanoserverl | set-VMNetworkAdapter -MacAddressSpoofing on


Determine Usage Scenarios for Gen1/Gen2 VMs
Generally, use Generation 2 VMs, except...
- VHD is not UEFI-compatible
- You plan to move your VM to Azure* (as of Jun'17 Azure supports only gen1 VMs)
- Your OS is not supported on Generation 2
- Your boot method is not supported on Generation 2

Enable Hyper-V remote ISO attachment
How to add a file share ISO to a Hyper-V VM
!!! Remember the machine needs to be rebooted for the change to take effect !!!

Integration Services & Resource Metering
Get-VMlntegrationService -ComputerName hypervl -VMName vm1
Enable-VMintegrationService ## with parameters
Enter-PSSession vm1
Get-ltemProperty "HKLM:\Software\Microsoft\Virtual Machine\Auto"
## look for > integrationServicesVersion : 10.0.14393 << this can be updated via WSUS
Get-Counter -Listset memory | select -expand counter
## look >> \Memory\Available Bytes
get-counter "\memory\available mbytes"
while ($true) { get-counter "\memory\available mbytes" ; Start-Sleep -s .5 }  ## every half a second
## exit ps-session
Get-VMMemory -ComputerName hyperv1 -VMName vm1
Set-VMMemory -ComputerName hyperv1 -VMName vm1 -startupBytes 4096MB
Enable-VMResourceMetering -ComputerName hypervl -VMName vm1
Measure-VM -ComputerName hyperv1 -VMName vm1 ## use | fl for more info
Measure-VM -ComputerName hyperv1 -VMName vm1 | select -expand harddiskmetrics
Measure-VM -ComputerName hyperv1 -VMName vm1 | select -expand networkmeteredtrafficreport
Set-VMProcessor -ComputerName hyperv1 -VMName vm1 -EnableHostResourceProtection $true


Configuring Hyper-V Virtual Machine NUMA Topology

Smart Paging in Hyper-V Dynamic Memory

Export and Import virtual machines

Implement Enhanced Session Mode
- Enables redirection of locally-attached devices like those used in RDP sessions (USB Camera, etc.)
- Enabled by default on hosts running Windows 8/8.1/10
- Disabled by default on hosts running Windows Server 2012/2012 R2/2016
- Not available for Generation 1 VMs and VMs running non-Windows OSs
- Guest VM must run Windows 8.1/10 or Windows Server 2012 R2/2016 and have Remote Desktop Services enabled

Server - Hyper-V Settings > Enhanced Session Mode Policy
User - Enhanced Session Mode

Implement Discrete Device Assignment (DDA)
- Enables supported PCI Express devices to be directly connected to a VM
- Used to bypass virtualization and increase performance for VM activities
- DDA is Microsoft's first attempt at pass-through similar to Citrix and VMware
- Used most often to pass-through GPU and NVMe drives to VMs
- Add-VMAssignableDevice cmdlet
Discrete Device Assignment - Description and background

Implement Secure Boot
- Feature of UEFI that ensures each component loaded during boot is digitally signed and validated
- Not supported on BIOS or Gen 1 VMs
- Validation is done against trusted certificates present in UEFI firmware
- Windows OS bootloader is signed by Microsoft at C:\Windows\Boot\EFI (bootmgfw.efi)
- Confirm-SecureBootUEFI
Secure Boot on Virtual Machines

Implement Secure Boot for Linux
- Disable secure boot
- Sign bootloader with Microsoft certificate at https://sysdev.Microsoft.com
- Sign bootloader with locally-trusted certificate and certificate trust chain

FreeBSD ntegration Services
- Integration Services distribution for FreeBSD is different than for Linux
- Unlike Linux, there is only one FreeBSD
- Unlike Linux, no subsequent "distributions"
- The FreeBSD Foundation is responsible for the OS kernel and all drivers and libraries
- Microsoft delivers Integration Services directly to the FreeBSD community for acceptance and inclusion in latest release
Microsoft Loves Linux Deep Dive #5: FreeBSD on Hyper-V

For Linux VMs on Hyper-V
- disable secure boot

Supported Linux and FreeBSD virtual machines for Hyper-V on Windows
Linux Integration Services Version 4.1 for Hyper-V << most distributions come with that installed OOB

install Integration Services (aka VMware Tools) - check supported versions!
- mount integration services iso to VM
- mount /dev/cdrom /media
- cd /media
- ./upgrade.sh
- /sbin/modinfo hv_vmbus << tells you version of installed Integration Services
- /sbin/modinfo hv_vmbus | grep version


.