-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUpdate-RKVM.ps1
More file actions
80 lines (68 loc) · 2.45 KB
/
Update-RKVM.ps1
File metadata and controls
80 lines (68 loc) · 2.45 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#requires –RunAsAdministrator
# Update-RKVM.ps1
# Updates an RK VM - new nics, etc
# run this in the Hyper-V Host
Function Update-RKVM {
[CmdletBinding()]
Param(
$VMName,
$CPUCount = 4,
$Memory = 4GB, # Memory in gb
$NHV = $False # Nested VIrtualisation
)
# Start of script
Write-Verbose "Update-RKVM - Updating a VM"
# Check VM Name specified
If ($null -eq $VMName) {
Write-Error 'No VM Name Specified - returning'
Return
}
# Get VM
$VM = Get-VM -VMName $VMname
Write-Verbose "VM [$VMName] found - updating"
# Stop it if it's running
If ($VM.State -eq 'Running') {
Stop-VM -VMName $VMName
Write-Verbose "Stopping VM: [$VMName]"
}
Else {
Write-Verbose "VM [$VMName] is NOT running"
}
# Set CPU Count
Set-VM -VMName $VMName -ProcessorCount $CPUCount
Write-Verbose "Setting CPU Count to: [$CPUCount]"
# Set memory
Write-Verbose "Setting VM Memory to: [$Memory]"
Set-VMMemory -VMName $VMName -DynamicMemoryEnabled $True -MinimumBytes $MEMORY -Startupbytes ($Memory + 128MB)
Write-Verbose "Setting Memory to : [$($memory/1GB) GB]"
# Expose virtualisation in the VM?
Set-VMProcessor -VMName $VMName -ExposeVirtualizationExtensions $NHV
Write-Verbose "VM $VMName to enable nested HyperV: [$NHV]"
# Add a second NIC and bind to External.
$NICS = Get-VMNetworkAdapter -VMName $VMName
if ($NICS.Count -eq 1) {
Write-Verbose 'Adding 2nd NIC and binding to External'
Add-VMNetworkAdapter -VMName $VMName -SwitchName External
}
else {
Write-Verbose "Second NIC already exists in $VMName"
}
# ALL DONE
Write-Verbose "Starting $VMName"
Start-VM -VMName $VMName
Write-Verbose "VM $VMName restarted"
}
# Example use:
Update-RKVM -VMName SRV1 -NHV $true -verbose -CPUCount 6
# Update-RKVM -VMName SRV2 -NHV $true -verbose -CPUCount 6 -memory 8GB
# Update-RKVM -VMName DC1 -NHV $true -verbose -CPUCount 6 -memory 8GB
# Update-RKVM -VMName DC2 -NHV $true -verbose -CPUCount 6 -memory 8GB
# Update-RKVM -VMName UKDC1 -NHV $true -verbose -CPUCount 6 -memory 8GB
# Update-RKVM -VMName HV1 -NHV $true -verbose -CPUCount 6
# Update-RKVM -VMName HV2 -NHV $true -verbose -CPUCount 6
# Update-RKVM -VMName CH1 -NHV $true -verbose -CPUCount 6
# Update-RKVM -VMName PSRV -NHV $true -verbose -CPUCount 6
# Update-RKVM -VMName FS2 -NHV $true -verbose -CPUCount 4
# Update-RKVM -VMName FS1 -NHV $true -verbose -CPUCount 4
# Update-RKVM -VMName SS1 -NHV $true -verbose -CPUCount 4
# Update-RKVM -VMName WSUS1 -NHV $true -verbose -CPUCount 4 -memory 8GB