-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_SQLServerLabMini.ps1
More file actions
146 lines (94 loc) · 4.46 KB
/
init_SQLServerLabMini.ps1
File metadata and controls
146 lines (94 loc) · 4.46 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
Param (
[string[]]$StartComputerName,
[string[]]$ConnectComputerName
)
<# Sample code to run this init script:
. .\init_SQLServerLabMini.ps1
. .\init_SQLServerLabMini.ps1 -Start DC, CLIENT -Connect CLIENT
#>
$ErrorActionPreference = 'Stop'
if ($PSVersionTable.PSVersion.Major -lt 7) {
throw "This script needs pwsh 7"
}
. .\MyAzureLab.ps1
# Name of resource group and location
# Will be used by MyAzureLab commands (so these are "global" variables)
$resourceGroupName = 'SQLServerLabMini'
$location = 'North Europe'
# Name and password of the initial account
$initUser = 'initialAdmin' # Will be used when creating the virtual maschines
$initPassword = 'initialP#ssw0rd' # Will be used when creating the virtual maschines and for the certificate
$initCredential = [PSCredential]::new($initUser, (ConvertTo-SecureString -String $initPassword -AsPlainText -Force))
# Show state of the resource group
Show-MyAzureLabResourceGroupInfo
# Read the configuration
. .\SQLServerLabMini\set_vm_config.ps1
# Start VMs
if ($StartComputerName) {
if ($StartComputerName -eq 'All') {
Start-MyAzureLabResourceGroup
} else {
Start-MyAzureLabResourceGroup -OnlyComputerName $StartComputerName
}
}
# Connect to VMs (always use the admin credential in this case)
if ($ConnectComputerName) {
Start-Sleep -Seconds 30
foreach ($computerName in $ConnectComputerName) {
Start-MyAzureLabRDP -ComputerName $computerName -Credential $credentials.Admin
}
}
# Don't do anything else
break
# To suppress the warnings about breaking changes:
# Update-AzConfig -DisplayBreakingChangeWarning $false
# To suppress information about cheaper regions:
# Update-AzConfig -DisplayRegionIdentified $false
# Daily tasks if the lab is fully set up:
#########################################
Start-MyAzureLabResourceGroup
Stop-MyAzureLabResourceGroup
# To use the PowerShell module ActiveDirectory in the CLIENT:
# Install-WindowsFeature -Name "RSAT-AD-PowerShell"
# I try to use the "normal" account for most of the tests and developments:
Start-MyAzureLabRDP -ComputerName CLIENT -Credential $credentials.User
# On the SQL2022 only the domain admin is able to connect via RDP:
Start-MyAzureLabRDP -ComputerName SQL2022 -Credential $credentials.Admin
# For testing dbatools, currently use admin account on CLIENT:
Start-MyAzureLabRDP -ComputerName CLIENT -Credential $credentials.Admin
# Just in case:
$psSession = New-MyAzureLabSession -ComputerName CLIENT -Credential $credentials.User
$psSession | Remove-PSSession
# Tasks to create and remove virtual maschines:
###############################################
# Show the configuration
$vmConfig | ConvertTo-Json
# Uses Microsoft.PowerShell.ConsoleGuiTools and needs some other object structures (so work in progress):
$vmConfig | Show-ObjectTree
# Create the VMs
. .\SQLServerLabMini\create_VMs.ps1
# Connect to client
# Just once:
# reg add "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client" /v "AuthenticationLevelOverride" /t "REG_DWORD" /d 0 /f
Start-MyAzureLabRDP -ComputerName DC -Credential $credentials.Admin
Start-MyAzureLabRDP -ComputerName CLIENT -Credential $credentials.User
Start-MyAzureLabRDP -ComputerName CLIENT -Credential $credentials.Admin
Start-MyAzureLabRDP -ComputerName CLIENT -Credential $credentials.SQLUser
Start-MyAzureLabRDP -ComputerName CLIENT -Credential $credentials.SQLAdmin
Start-MyAzureLabRDP -ComputerName SQL2022 -Credential $credentials.SQLAdmin
# To remove all virtual maschines:
##################################
Remove-MyAzureLabVM -All -Verbose
# The following commands are only used for initial setup or final destruction:
##############################################################################
# Creating resource group
$null = New-AzResourceGroup -Name $resourceGroupName -Location $location
# $null = Remove-AzResourceGroup -Name $resourceGroupName -Force
# Get-AzKeyVault -InRemovedState -WarningAction SilentlyContinue | ForEach-Object -Process { Remove-AzKeyVault -VaultName $_.VaultName -Location $_.Location -InRemovedState -Force }
# Creating key vault and certificate
New-MyAzureLabKeyVault
# Get-AzKeyVault -ResourceGroupName $resourceGroupName | Remove-AzKeyVault -Force
# Creating network and security group
New-MyAzureLabNetwork -HomeIP $homeIP
# Get-AzVirtualNetwork -ResourceGroupName $resourceGroupName | Remove-AzVirtualNetwork -Force
# Get-AzNetworkSecurityGroup -ResourceGroupName $resourceGroupName | Remove-AzNetworkSecurityGroup -Force