-
Notifications
You must be signed in to change notification settings - Fork 2
/
GetFtpInfo.ps1
354 lines (318 loc) · 14.7 KB
/
GetFtpInfo.ps1
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
$ErrorActionPreference = 'Stop'
$WarningPreference = 'SilentlyContinue'
$templateURI = 'C:/GitRepo/AVDAlerts/deploySubscription/solution.json'
# VARIABLES
$filetimestamp = Get-Date -Format "MM.dd.yyyy_THH.mm"
$OutputFile = './Parameters_' + $filetimestamp + '.json'
Write-Host "This script will help you collect the following information and build out your parameters file for deployment."
Write-Host "While mulitple storage resouces can be defined, you will only be prompted for a single option via this script" -ForegroundColor Yellow
# =================================================================================================
# Set Environment for Deployment
# =================================================================================================
Write-Host "Getting Azure Cloud list..." -ForegroundColor Yellow
$CloudList = (Get-AzEnvironment).Name
Write-Host "Which Azure Cloud would you like to deploy to?"
Foreach($cloud in $CloudList){Write-Host ($CloudList.IndexOf($cloud)+1) "-" $cloud}
$select = Read-Host "Enter selection"
$Environment = $CloudList[$select-1]
Write-Host "Connecting to Azure... (Look for minimized or hidden window)" -ForegroundColor Yellow
Connect-AzAccount -Environment $Environment | Out-Null
Clear-Host
# =================================================================================================
# Set Tenant for Deployment
# =================================================================================================
[array]$Tenants = Get-AzTenant
If ($Tenants.count -gt 1){
Write-Host "Which Azure Tenant would you like to deploy to?"
Foreach($Tenant in $Tenants){
Write-Host ($Tenants.Indexof($Tenant)+1) "-" $Tenant.Name
}
$TenantSelection = Read-Host "Enter selection"
$TenantId = ($Tenants[$TenantSelection-1]).Id
Clear-Host
}
else{$TenantId = $Tenants[0].Id}
# =================================================================================================
# Set Subscription for Deployment
# =================================================================================================
Write-Host "Which Azure Subscription would you like to deploy the AVD Metrics solution in?"
[array]$Subs = Get-AzSubscription -TenantId $TenantId
Foreach($Sub in $Subs){
Write-Host ($Subs.Indexof($Sub)+1) "-" $Sub.Name
}
$SubSelection = Read-Host "Enter selection"
$SubID = ($Subs[$SubSelection-1]).Id
Set-AzContext -Tenant $TenantId -Subscription $SubID | Out-Null
Clear-Host
# =================================================================================================
# Get distro email address
# =================================================================================================
$DistributionGroup = Read-Host "Provide the email address of the user or distribuition list for AVD Alerts (Disabled by default)"
Clear-Host
# =================================================================================================
# Get Alert Name Prefix
# =================================================================================================
$AlertNamePrefix = Read-Host "Provide the Alert Name Prefix you would like to use. To use the default of 'AVD-' just hit ENTER."
Clear-Host
# =================================================================================================
# Get Location to be used
# =================================================================================================
Write-Host "If you need a list of Locations you can also run the following at a PowerShell prompt:"
Write-Host "Connect-AzAccount; get-AzLocation | fl Location"
$Location = Read-Host "Enter the Azure deployment location (e.g. eastus)"
Clear-Host
# =================================================================================================
# Resource Group Name to be used
# =================================================================================================
Write-Host "By default a Resource Group will be created 'rg-avdmetrics-<environment>-<region>'"
Write-Host "Would you like to define you're own Resource Group Name or use an Existing?"
$selection = Read-Host "Y, N or E (existing)"
If($selection.ToUpper() -eq 'Y'){
Write-Host "Some examples are: rg-eastus2-avdmetrics, rg-avdalerts-eus2"
$RGName = Read-Host "Resource Group Name"
}
If($selection.ToUpper() -eq 'E'){
$RGList = Get-AzResourceGroup
$i = 1
Write-Host "Select one of your existing Resource Groups:"
Foreach($Item in $RGList){
Write-Host $i" -"($Item.ResourceGroupName)" ("($Item.Location)")"
$i++
}
$selection = Read-Host "Resource Group"
$RGName = $RGList[$selection-1].ResourceGroupName
}
Clear-Host
# =================================================================================================
# Environment to deploy (Prod, Dev, Test)
# =================================================================================================
Write-Host "What type of Environment Type is this being deployed to? (This is simply used in naming resources)"
Write-Host "P - Production"
Write-Host "D - Development"
Write-Host "T - Test"
$EnvType = Read-Host "Select the corresponding letter"
$EnvType = $EnvType.ToLower()
If(($EnvType -ne "p") -and ($EnvType -ne "d") -and ($EnvType -ne "t"))
{
Write-Host "You must select one of the above! Exiting!" -foregroundcolor Red
Break
}
Clear-Host
# =================================================================================================
# AVD Host Pool RG Names
# =================================================================================================
Write-Host "Getting AVD Host Pools in Subscription..."
$AVDResourceRG = ""
$RGs = @()
$AVDHostPools = Get-AzResource -ResourceType 'Microsoft.DesktopVirtualization/hostPools'
Foreach($item in $AVDHostPools){$RGs += $AVDHostPools.ResourceGroupName}
$RGs = $RGs | Sort-Object -Unique
If ($RGs.count -gt 1){
Write-Host "More than 1 RG found!"
$i=1
Foreach($RG in $RGs){
Write-Host $i" - "$RG
$i++
}
Write-Host "Select the number corresponding to the Resource Group containing your AVD HostPool Resources."
Write-Host " The script will find the Resource Groups with the corresponding VMs!" -ForegroundColor Yellow
#Write-Host "(For multiples type the number separated by a comma or 1,3,5 as an example)" #### TO HANDLE MULTIPLE LATER
$response = Read-Host
$AVDResourceRG = $RGs[$response-1]
}
Else {
Write-Host "Adding the only SINGLE Resource Group found with Host Pool resources:" $RGs
$AVDResourceRG = $RGs
}
Write-Host "..Getting Resource Groups with associated VMs... PLEASE WAIT!" -ForegroundColor Yellow
$HostPools = Get-AzWvdHostPool -ResourceGroupName $AVDResourceRG
$SessionHosts = @()
$AVDVMRGs = @()
$AVDResourceIDs = @()
Foreach($HostPool in $HostPools){
$CurrSessionHost = ((Get-AzWvdSessionHost -SubscriptionId $SubID -ResourceGroupName $AVDResourceRG -HostPoolName $HostPool.Name).Name -split '/')[1]
If($null -eq $CurrSessionHost){Write-Host "No Session Hosts Found in:" $HostPool.Name -ForegroundColor Yellow}
Else{
$DotLocation = $CurrSessionHost.IndexOf('.')
If($DotLocation -ne -1){$CurrSessionHost = $CurrSessionHost.Substring(0,$DotLocation)}
$AVDVMRGs += (Get-AzVM -Name $CurrSessionHost).ResourceGroupName
$SessionHosts += $CurrSessionHost
}
}
$AVDVMRGs = $AVDVMRGs | Sort-Object | Get-Unique
$AVDVMRGIds = @()
Foreach ($AVDVMRG in $AVDVMRGs){
$AVDVMRGIds += (Get-AzResourceGroup -Name $AVDVMRG).ResourceId
}
Foreach ($item in $AVDVMRGIds){
$AVDResourceIDs += $item
}
Clear-Host
# =================================================================================================
#Log Analytics
# =================================================================================================
Write-Host "Getting Log Analytics Workspaces in Subscription..."
$LogAnalyticsWorkspaces = Get-AzOperationalInsightsWorkspace
$i=1
Foreach($LAW in $LogAnalyticsWorkspaces){
Write-Host $i" -"($LAW.Name)
$i++
}
$response = Read-Host "Select the number corresponding to the Log Analytics Workspace containing AVD Metrics"
$LogAnalyticsWorkspace = $LogAnalyticsWorkspaces[$response-1].ResourceId
Clear-Host
# =================================================================================================
#Azure Storage Accounts
# =================================================================================================
Write-Host "Getting Azure Storage Accounts..."
$StorageAccts = $null
$StorageAcct = $null
[array]$StorageAccts = Get-AzStorageAccount
IF($StorageAccts.count -gt 0){
$i=1
Foreach($StorAcct in $StorageAccts){
Write-Host $i" -"($StorAcct.StorageAccountName)
$i++
}
Write-Host "Select the number corresponding to the Storage Account containing AVD related file shares"
$response = Read-Host "For multiples seperate each number with a comma (i.e. 1,3,4)`n"
if(!$response){
$StorageAcct = @()
}
else{
$selection = $response -split ","
foreach($entry in $selection){$StorageAcct += @("$($StorageAccts[$entry-1].Id)")}
}
}
ELSE {
$StorageAcct = @()
}
Clear-Host
# =================================================================================================
#ANF Volumes
# =================================================================================================
Write-Host "Getting Azure NetApp Filer Pools\Volumes..."
$ANFVolumeResources = $null
$ANFVolumeResource = $null
# Need RG, AccountName and Pool Name
[array]$ANFVolumeResources = Get-AzResource -ResourceType 'Microsoft.NetApp/netAppAccounts/capacityPools/volumes'
IF($ANFVolumeResources.count -eq 0){
$ANFVolumeResource = @()
}
ELSEIF($ANFVolumeResources.count -eq 1){
Write-Host "Only found a single ANF Volume and capturing:`n`t" ($ANFVolumeResources.Name -split '/')[1]"\"($ANFVolumeResources.Name -split '/')[2]
[array]$ANFVolumeResource = $ANFVolumeResources[0].ResourceId}
Else{
$i=1
Foreach($ANFVolRes in $ANFVolumeResources){
$ANFVolName = ($ANFVolRes.Name -split '/')[2]
$ANFPool = ($ANFVolRes.Name -split '/')[1]
Write-Host $i" - "$ANFPool"\"$ANFVolName
$i++
}
Write-Host "Select the number corresponding to the Azure NetApp Capacity Pool / Volume."
$response = Read-Host "For multiples seperate each number with a comma (i.e. 1,3,4)`n"
$selection = $response -split ","
foreach($entry in $selection){[array]$ANFVolumeResource += $ANFVolumeResources[$entry-1].ResourceId}
}
Clear-Host
# =================================================================================================
# Desired Tags
# =================================================================================================
Write-Host "Azure Tags are in a key pair format. Please input the Tag you would like to add to the resources."
Write-Host "Simply hit ENTER to contine adding mulitple tag key pairs and type X, to exit input!"
Write-Host "(i.e Name:Value or Environment:Lab)"
$Tags = @{}
$AddMore = $true
do {
$UsrInput = Read-Host "Enter key / value pairs"
If (($UsrInput.ToUpper() -eq "X") -or ($UsrInput -eq "")){$AddMore = $false}
else{
$Key = $UsrInput.Split(':')[0]
$Value = $UsrInput.Split(':')[1]
$Tags += @{$Key="$Value"}
}
} while ($AddMore)
# Accomodate option for Alert Name Prefix if empty, use default
if ($AlertNamePrefix -eq ''){$AlertNamePrefix = "AVD-"}
# Output Tags in JSON format
$Parameters = [pscustomobject][ordered]@{
'$schema' = "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#"
contentVersion = "1.0.0.0"
parameters = [pscustomobject][ordered]@{
AlertNamePrefix = [pscustomobject][ordered]@{
value = $AlertNamePrefix
}
DistributionGroup = [pscustomobject][ordered]@{
value = $DistributionGroup
}
Environment = [pscustomobject][ordered]@{
value = $EnvType
}
Location = [pscustomobject][ordered]@{
value = $Location
}
UserResourceGroup = [pscustomobject][ordered]@{
value = $RGName
}
LogAnalyticsWorkspaceResourceId = [pscustomobject][ordered]@{
value = $LogAnalyticsWorkspace
}
SessionHostsResourceGroupIds = [pscustomobject][ordered]@{
value = $AVDResourceIDs
}
StorageAccountResourceIds = [pscustomobject][ordered]@{
value = $StorageAcct
}
ANFVolumeResourceIds = [pscustomobject][ordered]@{
value = $ANFVolumeResource
}
Tags = [pscustomobject][ordered]@{
value = $Tags
}
}
}
$JSON = $Parameters | ConvertTo-Json -Depth 5
$JSON | Out-File $OutputFile
Clear-Host
# Write Output for awareness
Write-Host "Azure Parameters information saved as... `n$OutputFile" -foregroundcolor Green
# Summary:
Clear-Host
Write-Host "Summary of Selections" -ForegroundColor Green
Write-Host "====================================================================================" -ForegroundColor Green
Write-Host "Subscription for Alerts Solution:" -ForegroundColor Cyan
Write-Host "`t$SubId"
Write-Host "AVD Alert Name Prefix:" -ForegroundColor Cyan
Write-Host "`t$AlertNamePrefix"
Write-Host "Email for Alerts:" -foregroundcolor Cyan
Write-Host "`t$DistributionGroup"
Write-Host "Environment Type:" -foregroundcolor Cyan
Write-Host "`t$EnvType"
Write-Host "Location:" -foregroundcolor Cyan
Write-Host "`t$Location"
Write-Host "Log Analytics Workspace:" -foregroundcolor Cyan
Write-Host "`t$LogAnalyticsWorkspace"
Write-Host "Resource Group Name (if custom):" -foregroundcolor Cyan
Write-Host "`t$RGName"
Write-Host "Azure Files Storage:" -foregroundcolor Cyan
foreach($item in $StorageAcct){Write-Host "`t$item"}
Write-Host "NetApp Files Volume:" -foregroundcolor Cyan
foreach($item in $ANFVolumeResource){Write-Host "`t$item"}
Write-Host "Host Pool VM Resource Groups:" -foregroundcolor Cyan
foreach($item in $AVDResourceIDs){Write-Host "`t$item"}
Write-Host "Tags for resources:" -foregroundcolor Cyan
Write-Output $Tags
Pause
# Launch Deployment
$ToDeploy = Read-Host "`nDeploy Now? (Y or N)"
If($ToDeploy.ToUpper() -eq 'Y'){
Write-Host "Launching Deployment..."
New-AzDeployment -Name "AVD-Alerts-Solution" -TemplateUri $templateURI -TemplateParameterFile $OutputFile -Location $Location -Verbose
}
else {
Write-Host "Exiting..." -ForegroundColor Yellow
Write-Host "Please use the following to deploy with your pre-created Paramaters file: $OutputFile"
Write-Host """New-AzDeployment -Name "AVD-Alerts-Solution" -TemplateUri $templateURI -TemplateParameterFile $OutputFile -Location $Location"""
}
New-AzDeployment -Name "AVD-Alerts-Solution" -TemplateFile C:\GitRepo\AVDAlerts\deploySubscription\solution.bicep -TemplateParameterFile $OutputFile -Location $Location -Verbose