PowerShell Guide – Standalone Hyper-V Server

Last modified date: 2019-11-01
The following are the PowerShell steps to set up a standalone Hyper-V server.
There is a bit of CMD in there too.
# Rename Server
Rename-Computer -NewName Hyper-V –Restart

# Check Server Name Post Reboot
$(Get-WmiObject Win32_Computersystem).name

# Make a Temp Directory - We always switch to this folder before moving on
MkDir \Temp
CD \Temp # Join Domain Add-Computer -DomainName DOMAIN.local -Credential DOMAIN\ADMIN -OUPath "OU=Hyper-V Servers,OU=Computers,OU=YEG-Business,DC=Corp,DC=DOMAIN,DC=Com" -Restart # Swap File in CMD wmic.exe computersystem where name="S2D-HV01" set AutomaticManagedPagefile=False wmic.exe pagefileset where name="c:\\pagefile.sys" set InitialSize=4199,MaximumSize=4199 shutdown -r -t 0 # Crash Dump Set-ItemProperty –Path HKLM:\System\CurrentControlSet\Control\CrashControl –Name CrashDumpEnabled –value 1 Get-ItemProperty –Path HKLM:\System\CurrentControlSet\Control\CrashControl –Name CrashDumpEnabled Set-ItemProperty –Path HKLM:\System\CurrentControlSet\Control\CrashControl –Name FilterPages –value 1 Get-ItemProperty –Path HKLM:\System\CurrentControlSet\Control\CrashControl –Name FilterPages # NIC Lbfo Teaming (2019-11-01: Will be replaced by SET Switch setup soon) Get-NetAdapter New-NetLbfoTeam -Name vSwitch -TeamMembers * # Takes all NIC ports # OR assuming 2 NICs with two ports each (augment if 4 ports per NIC) Get-NetAdapter | Sort MacAddress New-NetLbfoTeam -Name vSwitch -TeamMembers "LowestMacPort NIC 0","LowestMacPort NIC 1" -Confirm:$False New-NetLbfoTeam -Name vSwitch -TeamMembers "NextLowestMacPort NIC 0","NextLowestMacPort NIC 1" -Confirm:$False Get-NetLbfoTeam | FL # Set Static IP Set-NetIPInterface -InterfaceAlias vSwitch -DHCP Disabled
Remove-NetIPAddress -InterfaceAlias vSwitch -Confirm:$false New-NetIPAddress -InterfaceAlias vSwitch -IPAddress 192.168.X.10 –DefaultGateway 192.168.X.1 -PrefixLength 24 Set-DnsClientServerAddress -InterfaceAlias vSwitch -ServerAddresses 192.168.X.254,192.168.X.252 IPConfig /RegisterDNS # Install the Hyper-V Role Install-WindowsFeature Hyper-V,Hyper-V-Tools,Hyper-V-PowerShell -IncludeAllSubFeature -IncludeManagementTools -Restart # Set up a Shared with the Host OS virtual Switch New-VMSwitch –Name vSwitch –NetAdapterName vSwitch –AllowManagementOS 1 # Set up a Virtual Switch _NOT_ shared with Host OS *** Will Knock IP Out *** New-VMSwitch –Name vSwitch –NetAdapterName "vSwitch" –AllowManagementOS 0 # Enable Enhanced Session Mode Set-VMhost -EnableEnhancedSessionMode $TRUE # Set the Default VM VHDX and Configuration Files Locations Set-VMHost -VirtualHardDiskPath "X:\Hyper-V\Virtual Hard Disks" –VirtualMachinePath "X:\Hyper-V" Get-VMHost | fl VirtualHardDiskPath,VirtualMachinePath