These are the steps:
- Install Windows
Windows 2019 Data Center Edition is the standard as of May 20, 2022
Certain hardware may require slipstreamed ISO’s to load RAID drivers so that the installation wizard would recognize the underlying hardware
Install Windows with GUI. Although, headless Windows would still work, our Admins prefer to have GUI, boo - Setup Network connectivity
Obtain a static IP for the server
Assign an IP for new server using
Setup Interface with static IP, Gateway, and DNS - Ensure that machine is accessible to VMM on these ports
Ports required by SCVMM:
TCP/22
TCP/80
TCP/135
TCP/139
TCP/445
TCP/443
TCP/623
TCP/1433
TCP/5985
TCP/5986
TCP/8530
TCP/8531
TCP/8100
TCP/8101
TCP/8102
TCP/49152 to TCP/65535
Ports required by Prometheus Windows Exporter:
TCP/9182 - Enable RDP
This feature would automatically be installed when a machine joins the domain. However, we’re ensuring that the hardware and OS would not go into a recovery loop due to driver issues. Hence, we would be patching Windows and attempting enable its Hyper-V features as a precursor to joining the machine to to domain, only if the machine is stable after these functions are added. - Disable Startup repair
Run this command: bcdedit /set {current} recoveryenabled no - Update Windows
There’s a PowerShell method to updating Windows directly from Microsoft
Alternative, the equivalent GUI method would suffice - Install Hyper-V Features: Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
Be advised that Windows will reboot after this command
If there were any driver conflicts, Windows would go into a recovery loop. Hopefully, that doesn’t happen to the machine you’re preparing - Join Domain
-
Run these PowerShell Command as Administrator
# Install Chocolatey
if (!(Get-Command choco.exe -ErrorAction SilentlyContinue)) {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))}
# Defining $ENV:ChocotaleyInstall so that it would be called by refreshenv
$ENV:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.."
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
Update-SessionEnvironment
# Add Private Repo
$privateRepoName='kimconnectrepo'
$privateRepoUrl='https://choco.kimconnect.com/chocolatey'
$priority=1
$privateRepo="'$privateRepoName' -s '$privateRepoUrl' --priority=$priority"
choco source add -n=$privateRepo
- Uninstall Windows Defender
Run this command:Remove-WindowsFeature Windows-Defender
- Install Enterprise Antivirus
- Install Prometheus Windows Exporter
Use Chocolatey to install Prometheus Windows_Exporterchoco install prometheus-windows-exporter.install -y --ignore-checksums
$null=& sc.exe failure $serviceName reset= 30 actions= restart/100000/restart/100000/""/300000
Set-Service -Name $serviceName -StartupType 'Automatic'
Enabling Collectors for a Hyper-V Server
$serviceName='Windows_Exporter'
$enabledCollectors='os,cpu,cs,logical_disk,net,tcp,hyperv,service,textfile'
$switches=" --log.format logger:eventlog?name=$serviceName --collectors.enabled $enabledCollectors"
function modifyService{
param(
$serviceName,
$switches
)
$wmiService=Get-WmiObject win32_service| ?{$_.Name -like "*$serviceName*"}
$exePath=[regex]::match($wmiService.PathName,'\"(.*)\"').groups[1]
$binarySwitches='\"' + $exePath + '\"' + $switches
sc.exe config $serviceName binpath= $binarySwitches
sc.exe qc windows_exporter
restart-service $serviceName
}
# Local execution
modifyService $serviceName $switches
- Install Failover Clustering Features
# After restart, install Failover clustering features
Install-WindowsFeature Failover-Clustering -IncludeManagementTools; Install-WindowsFeature RSAT-Clustering-MGMT,RSAT-Clustering-PowerShell,Multipath-IO
-
Setup NIC Teaming (if appropriate)
# Check Teaming setup
Get-NetLbfoTeam
# Initialize Teaming, if required
$teamName='Team1'
$vlanId=100
Add-NetLbfoTeamNIC -Team $teamName -VlanID $vlanId
# Set Teaming mode, if required
$teamName='Team1'
$teamMode='LACP'
$lbAlgorithm='Dynamic'
Set-NetLbfoTeam -Name $teamName -TeamingMode $teamMode -LoadBalancingAlgorithm $lbAlgorithm
# Add Team members, if required
$teamName='Team1'
$nicTeamMembers='NIC1','NIC2'
$nicTeamMembers|%{Add-NetLbfoTeamMember -Name $_ -Team $teamName}
# Check Teaming setup, if required
Get-NetLbfoTeam
# Check NIC names
Get-NetAdapter
- Enable WinRM:
Enable-PSRemoting -Force
- Enable CredSSP:
Enable-WSManCredSSP -Role Server -Force
- Create New Virtual Switch(es)
$switchName='External-Connection' # change this label to reflect the actual vSwitch name to be added
$adapterName='TEAM1' # change this value to reflect the correct interface
$vlanId=101 # change this to the correct VLAN
function addVirtualSwitch($switchName,$adapterName,$vlanId){
New-VMSwitch -name $switchName -NetAdapterName $adapterName -AllowManagementOS $true
if($vlanId){
Get-VMNetworkAdapter -SwitchName $switchName -ManagementOS|Set-VMNetworkAdapterVlan -Access -VlanId $vlanId
}
}
addVirtualSwitch $switchName $adapterName $vlanId
- Include appropriate Admins
# Example for HQ
$admins=@(
"$env:USERDOMAIN\$($env:computername)$",
"$env:USERDOMAIN\service-hv",
"$env:USERDOMAIN\service-vmm"
)
Add-localgroupmember -group Administrators -member $admins
- Join Node to Cluster
# Example
$clusterName='hyperv-cluster'
Add-ClusterNode -Name $env:computername -Cluster $clusterName
- Install VMM Agent
The easy method:# Install VMM Agent
$vmmServer='hq-vmm01' # change this value to reflect the correct VMM node
$version='10.19.2591.0' # change to value to reflect the latest expected version
$agentMsiFile="\\$vmmServer\C$\Program Files\Microsoft System Center\Virtual Machine Manager\agents\amd64\$version\vmmAgent.msi"
# Installing VMM Agent using its MSI File
$file=gi $agentMsiFile
$DataStamp = get-date -Format yyyyMMddTHHmmss
$logFile ="C:\" + '{0}-{1}.log' -f $file.name,$DataStamp
$MSIArguments = @(
"/i"
('"{0}"' -f $file.fullname)
"/qn"
"/norestart"
"/L*v"
$logFile
)
Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow
- Add This New Hyper-V Node to VMM
Access VMM as Administrator > Navigate to Fabric > select the appropriate cluster > right-click the newly introduced node > Associate with Cluster > Done