PowerShell Guide – Standalone Hyper-V Server

Last modified date: 2018-07-19

The following are the PowerShell steps to set up a standalone Hyper-V server. There is a bit of CMD in there too.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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

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