-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathInitialize-Module.ps1
More file actions
537 lines (469 loc) · 28.9 KB
/
Copy pathInitialize-Module.ps1
File metadata and controls
537 lines (469 loc) · 28.9 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
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# This file is used for setting the migration settings.
#
# Please Read the blog post at https://mspp.io/automated-it-glue-to-hudu-migration-script/ before running this script
# Version 2.0.0-beta
# Updated 07/04/2023
# If you found this script useful please consider sponsoring me at https://github.com/sponsors/lwhitelock?frequency=one-time
#
# References
# Determine image type https://devblogs.microsoft.com/scripting/psimaging-part-1-test-image/
# Parsing HTML https://stackoverflow.com/questions/28497902/finding-img-tags-in-html-files-in-powershell
# Nice Base64 conversion https://www.aaron-powell.com/posts/2010-11-07-base64-encoding-images-with-powershell/
#
# Thank you!
# Luke Whitelock - Primary creator of the ITGlue Migration script and HuduAPI Powershell Module
# John Duprey - Adding file and image uploads to the Migration script, and heavy contributor to the HuduAPI Powershell Module
# Mendy Green - Adding URL rewrite, TOTP Seed imports, improved resilency in the migration, and contributor to the HuduAPI Powershell module
#
# Upcoming Changes
# Convert to a full blown module, prompts for interactive migration experience, save settings to an outside file for secure sharing
# Add/enhance the migration areas to use the new API features of Hudu
param(
[Parameter(Mandatory=$true)]
[ValidateSet("Full", "Lite")]
[string] $InitType
)
if ((get-host).version.major -ne 7) {
Write-Host "Powershell 7 Required" -foregroundcolor Red
exit 1
}
if ($MyInvocation.InvocationName -eq '.') {
Write-Host "Script was dot-sourced" -ForegroundColor Green
} else {
Write-Host "Script was executed without dot-sourcing, this is the recommended method of running the script to ensure settings are retained in the session" -ForegroundColor Yellow; write-warning "exiting to prevent issues later on, please dot-source the script by running `. .\ITGlue-Hudu-Migration.ps1` from powershell 7 or using the provided ITGlue-Hudu-Migration.exe frontend.";
exit 1
}
############################### Settings ###############################
# Define the path to the settings.json file in the user's AppData folder
# Determine top part of settings path
if($IsWindows){
$settingsTop = $env:APPDATA
} else {
$settingsTop = Join-Path "$home" ".config"
}
if (-not (Get-Command -Name Get-EnsuredPath -ErrorAction SilentlyContinue)) { . $PSScriptRoot\Public\Init-OptionsAndLogs.ps1 }
$debugfolder = $debugFolder ?? $(Get-EnsuredPath -path $(join-path $(Resolve-Path .).path "debug"))
# Define the path to the settings.json file in the detected platform's folder:
# Running on Windows will save to the user's AppData
# Running on Linux/macOS will save to `.config` in the user's HOME directory
# Something awesome will be here soon.
$settingsFiles = $settingsFiles ?? $(Get-Item "$settingsTop\HuduMigration\*\settings.json")
$defaultSettingsPath = $defaultSettingsPath ?? "$settingsTop\HuduMigration\settings.json"
# Function to read back securely stored keys used in the settings.json file
function ConvertSecureStringToPlainText {
param (
[Parameter(Mandatory=$true)]
[System.Security.SecureString] $SecureString
)
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString)
$plainText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR)
return $plainText
}
# Prompt the user for various settings and save the responses
function CollectAndSaveSettings {
# Create a hash table to store the settings
$settings = $settings ?? @{}
# 1. Unser Entry- Urls
Write-Host "Settings- URLs:" -ForegroundColor Yellow
$settings.HuduBaseDomain = $settings.HuduBaseDomain ??
$((Read-Host -Prompt 'Set the base domain of your Hudu instance (e.g https://myinstance.huducloud.com)') -replace '[\\/]+$', '') -replace '^(?!https://)', 'https://'
$settings.ITGURL = $settings.ITGURL ??
$((Read-Host -Prompt 'Set the domain of your ITGlue instance (e.g https://your-company.itglue.com)') -replace '[\\/]+$', '') -replace '^(?!https://)', 'https://'
$settings.ITGAPIEndpoint = $settings.ITGAPIEndpoint ??
$(Select-ObjectFromList -objects @("https://api.itglue.com", "https://api.eu.itglue.com", "https://api.au.itglue.com") -message "Select ITGlue API Endpoint for your instance/region")
$customBrandedDomain = $customBrandedDomain ??
$(Read-Host -Prompt "Do you have additional hostnames you'd like to include in the URL Replacement? For example custom branded ITGlue Domain Name. (y/n)").ToLower().Trim()
$instance = $settings.ITGURL.replace('https://','')
if ($customBrandedDomain.ToLower() -eq 'y') {
$settings.ITGCustomDomains = Read-Host -Prompt "Please enter comma separated list of URLs to check for, following the same format of the main domain URL. If only one, don't include the comma."
}
# 2. User-Entry- Secrets
Write-Host "Settings- Secrets:" -ForegroundColor Yellow
$HuduAPIKey = $HuduAPIKey ?? ""
$ITGKey = $ITGKey ?? ""
while ($HuduAPIKey.Length -ne 24) {
$HuduAPIKey = (Read-Host -Prompt "Get a Hudu API Key from $($settings.HuduBaseDomain)/admin/api_keys").Trim()
if ($HuduAPIKey.Length -ne 24) {
Write-Host "This doesn't seem to be a valid Hudu API key. It is $($HuduAPIKey.Length) characters long, but should be 24." -ForegroundColor Red
}
}
while ($ITGKey.Length -notin 100..105) {
$ITGKey = (Read-Host -Prompt 'Enter your ITGlue API Key (must have password access). Should be 101-104 characters.').Trim()
if ($ITGKey.Length -notin 101..105) {
Write-Host "This doesn't seem to be a valid ITGlue API key. It is $($ITGKey.Length) characters long, but should be 101-104." -ForegroundColor Red
}
}
$settings.ITGKey = ConvertTo-SecureString -String $ITGKey -AsPlainText -Force | ConvertFrom-SecureString
$settings.HuduAPIKey = ConvertTo-SecureString -String $HuduAPIKey -AsPlainText -Force | ConvertFrom-SecureString
# 3. User-Entry Global KB Settings
Write-Host "Settings- Global KnowledgeBase:" -ForegroundColor Yellow
$settings.InternalCompany = $settings.InternalCompany ??
$(Read-Host 'Enter the exact name of the ITGlue Organization that represents your Internal Company ').ToString().Trim()
if ($null -eq $settings.PlaceInternalDocsInInternalCompany) {
while ($null -eq $settings.PlaceInternalDocsInInternalCompany) {
$internalDocsChoice = $(Read-Host -Prompt 'Do you want documents from your Internal Company to stay under that company instead of going to Global KB? [Default behavior is N/$false] (y/n)').ToString().Trim().ToLower()
switch ($internalDocsChoice) {
{ $_ -in @('y','yes') } { $settings.PlaceInternalDocsInInternalCompany = $true; break }
{ $_ -in @('n','no') } { $settings.PlaceInternalDocsInInternalCompany = $false; break }
default { Write-Host "Please re-enter, y or n" }
}
}
}
if ($true -ne $settings.PlaceInternalDocsInInternalCompany) {
$settings.GlobalKBFolder = $settings.GlobalKBFolder ??
""
while ($settings.GlobalKBFolder.Length -ne 1 -or $settings.GlobalKBFolder.ToLower() -notin @('y','n')) {
$settings.GlobalKBFolder = $(Read-Host -Prompt 'Do you want all documents in Global KB to be placed into a subfolder? (y/n)').ToString().Trim().ToLower()
if ($settings.GlobalKBFolder -notin @("y","n")){
Write-Host "Please re-enter, y or n"
}
}
Write-Host "The documents from the company $($settings.InternalCompany) will be migrated to Hudu's Global KB section " -ForegroundColor Cyan
} else {
Write-Host "The documents from the company $($settings.InternalCompany) will stay under that company in Hudu" -ForegroundColor Cyan
}
$settings.ConPromptPrefix = $settings.ConPromptPrefix ??
$(Read-Host "Would you like a Prefix in front of ️Configuration names️ created in Hudu? This can make it easy to review and you can rename them later. Enter the prefix here, otherwise leave it blank. (e.g. ITGlue-)")
$settings.FAPromptPrefix = $settings.FAPromptPrefix ??
$(Read-Host "Would you like a Prefix in front of Asset Layout names created in Hudu? This can make it easy to review and you can rename them later. Enter the prefix here, otherwise leave it blank. (e.g. ITGlue-)")
$settings.IncludeITGlueID = $settings.IncludeITGlueID ?? [bool]$($(Select-ObjectFromList -message "would you like to include ITGlue ID in your contacts, locations, and configurations layouts?" -objects @($true,$false) -allowNull $false) ?? $true)
# 4. User-Entry Paths and Folders
Write-Host "️Settings- Paths and Folders:" -ForegroundColor Yellow
$settings.ITGLueExportPath = $settings.ITGLueExportPath ??
$(Read-Host 'Enter the path of the ITGLue Export. (e.g. C:\Temp\ITGlue\Export) ️')
$settings.MigrationLogs = $settings.MigrationLogs ??
$(Read-Host "Enter the path for the migration logs, or press enter to accept the Default path ($settingsTop\HuduMigration\$instance\MigrationLogs)")
# Fallback for Migrationlogs setting
if (!($settings.MigrationLogs)) {
$settings.MigrationLogs = "$settingsTop\HuduMigration\$instance\MigrationLogs"
}
# Ensure folder is created for settings file
if (!(Test-Path -Path "$settingsTop\HuduMigration\$instance")) { New-Item "$settingsTop\HuduMigration\$instance" -ItemType Directory }
# Verify settings, save or exit and retry
$reenterChoice = $reenterChoice ??
$(Select-ObjectFromList -message "Do these settings look alright? $(($settings | ConvertTo-Json -depth 4).ToString())\n-If you choose to re-enter, changes made will not be saved" -objects @("Continue", "Re-Enter"))
if ($reenterChoice -eq "Continue") {
Write-Host "Saving Settings to $defaultSettingsPath"
# Convert the hash table to JSON
$json = $settings | ConvertTo-Json
$json | Out-File -FilePath $defaultSettingsPath
} else {
Clear-Host
Write-Host "reinvoke script when you're ready!..." -ForegroundColor Yellow
exit
}
}
function UpdateSavedSettings {
param(
$newSettings
)
if ($settingsPath) {
if (Test-Path $settingsPath) {
# Convert the hash table to JSON
Write-Host "️Overwriting existing settings file with updated settings." -ForegroundColor Cyan
$json = $newSettings | ConvertTo-Json
$json | Out-File -FilePath $settingsPath
}
else {
Write-Host "Creating new settings file in $settingsPath" -ForegroundColor Yellow
$json = $newSettings | ConvertTo-Json
$json | Out-File -FilePath $settingsPath
}
}
else {
if (Test-Path $defaultSettingsPath) {
# Convert the hash table to JSON
Write-Host "️Overwriting existing settings file with updated settings." -ForegroundColor Cyan
$json = $newSettings | ConvertTo-Json
$json | Out-File -FilePath $defaultSettingsPath
}
else {
Write-Host "Creating new settings file in $defaultSettingsPath" -ForegroundColor Yellow
$json = $newSettings | ConvertTo-Json
$json | Out-File -FilePath $defaultSettingsPath
}
}
}
# Prompt the user for a settings file
# Prompt the user for a settings file
function PromptForSettingsPath {
param(
[switch]$Default
)
if ($Default) {
$userPath = Read-Host -Prompt "Enter the full path to the settings.json file, or press Enter to use the default settings file ($defaultSettingsPath)"
} else {
$userPath = Read-Host -Prompt '️Enter the full path to the settings.json file.'
}
if ($userPath -eq '') {
$userPath = $defaultSettingsPath
$fileNotExistMessage = 'The default settings file does not exist. Please specify a path.'
} else {
$fileNotExistMessage = 'The specified path does not exist or is not accessible. Please try again.'
}
if (Test-Path -Path $userPath) {
return $userPath
} else {
Write-Warning $fileNotExistMessage
return PromptForSettingsPath
}
}
# Ask the user what they want to do
if ($environmentSettings -and $InitType -eq 'Lite') {
Write-Host "Lite init and settings detected."
}
else {
$choice = $choice ?? $(Read-Host -Prompt "Do you want to `n(I)mport `n settings or start from `n(N)ew ?")
switch ($choice) {
'I' {
if (Test-Path -Path $defaultSettingsPath) {
Write-Host "Default settings file found at $defaultSettingsPath" -ForegroundColor Cyan
$importChoice = $importChoice ?? $(Read-Host -Prompt "Do you want to use the `n(D)efault settings`n file or `n(S)pecify`n a different path?")
switch ($importChoice) {
'D' {
Write-Host "Importing settings from $defaultSettingsPath" -ForegroundColor Yellow
$environmentSettings = Get-Content -Path $defaultSettingsPath | ConvertFrom-Json -Depth 50
}
'S' {
$settingsPath = PromptForSettingsPath -Default
Write-Host "Importing settings from $settingsPath" -ForegroundColor Yellow
$environmentSettings = Get-Content -Path $settingsPath | ConvertFrom-Json -Depth 50
}
default {
Write-Host 'Invalid choice. Please choose (D)efault or (S)pecify.'
}
}
} else {
$settingsPath = PromptForSettingsPath
Write-Host "Importing settings from $settingsPath" -ForegroundColor Yellow
$environmentSettings = Get-Content -Path $settingsPath | ConvertFrom-Json -Depth 50
}
}
'N' {
Write-Host "Starting with a new settings file" -ForegroundColor Cyan
CollectAndSaveSettings
$environmentSettings = Get-Content -Path $defaultSettingsPath | ConvertFrom-Json -Depth 50
}
default {
throw 'Invalid choice. Please choose (I)mport or (N)ew '
}
}
}
############################### API Settings ###############################
# Hudu
# Get a Hudu API Key from https://yourhududomain.com/admin/api_keys
try {
$HuduAPIKey = ConvertSecureStringToPlainText -SecureString ($environmentSettings.HuduAPIKey|ConvertTo-SecureString)
}
catch {
Write-Host "Your Hudu API Key is not readable!!!" -ForegroundColor Yellow
$HuduAPIKey = Read-Host -Prompt "Enter the Hudu API Key from $($environmentSettings.HuduBaseDomain)/admin/api_keys"
$environmentSettings.HuduAPIKey = ConvertTo-SecureString -String $HuduAPIKey -AsPlainText -Force | ConvertFrom-SecureString
UpdateSavedSettings -newSettings $environmentSettings
}
# Set the base domain of your Hudu instance without a trailing /
$HuduBaseDomain = $environmentSettings.HuduBaseDomain
# IT Glue - MAKE SURE TO USE AN API KEY WITH PASSWORD ACCESS
$ITGAPIEndpoint = $environmentSettings.ITGAPIEndpoint
try {
$ITGKey = ConvertSecureStringToPlainText -SecureString ($environmentSettings.ITGKey|ConvertTo-SecureString)
}
catch {
Write-Host "Your ITG API Key is not readable!!!" -ForegroundColor Yellow
$ITGKey = Read-Host 'Enter your ITGlue API Key. MAKE SURE TO USE AN API KEY WITH PASSWORD ACCESS'
$environmentSettings.ITGKey = ConvertTo-SecureString -String $ITGKey -AsPlainText -Force | ConvertFrom-SecureString
UpdateSavedSettings -newSettings $environmentSettings
}
#Enter your primary IT Glue internal URL
$ITGURL = $environmentSettings.ITGURL
# IT Glue Internal Company Name
$InternalCompany = $environmentSettings.InternalCompany
$PlaceInternalDocsInInternalCompany = [bool]$environmentSettings.PlaceInternalDocsInInternalCompany ?? $false
$ITGLueExportPath = $environmentSettings.ITGLueExportPath
# Choose if you want to resume previous attempts from the last successful section
while ($resumeQuestion -notin ('yes','no')) {
$resumeQuestion = Read-Host "Would you like to resume a previous migration? (yes/no)"
}
$ResumePrevious = if ($resumeQuestion -eq 'yes') {$true} else {$false}
$GlobalKBFolder = if ($PlaceInternalDocsInInternalCompany) { $null } else { $environmentSettings.GlobalKBFolder }
# These settings should only run when doing a full settings initialization.
if ($InitType -eq 'Full') {
############################### Company Settings ###############################
while ($ImportCompanies -notin (1,2)) {$ImportCompanies = Read-Host "1) Import Companies `n2) Skip Companies`n(1/2)"}
switch ($ImportCompanies) {
"1" {$ImportCompanies = $true}
"2" {$ImportCompanies = $false}
}
############################### Location Settings ###############################
while ($ImportLocations -notin (1,2)) {$ImportLocations = Read-Host "1) Import Locations `n2) Skip Locations`n(1/2)"}
switch ($ImportLocations) {
"1" {$ImportLocations = $true}
"2" {$ImportLocations = $false}
}
# The asset layout name how locations will appear in Hudu
$LocImportAssetLayoutName = $LocImportAssetLayoutName ?? "Locations"
# The font awesome name for the locations icon in Hudu
$LocImportIcon = "fas fa-building"
# Here set two arrays of the different names you have used to identify the primary location in both ITGlue And Hudu
$ITGPrimaryLocationNames = @("Primary Address", "Main", "Head Office", "Main Office")
$HuduPrimaryLocationNames = @("Primary Address")
############################### Domain / Website Settings ###############################
while ($ImportDomains -notin (1,2)) {$ImportDomains = Read-Host "Domains are used for Website, DNS and SSL Monitoring.`n 1) Import Domains`n 2) Skip Domains`n(1/2)"}
switch ($ImportDomains) {
"1" {$ImportDomains = $true}
"2" {$ImportDomains = $false}
}
while ($MergedOrganizationTypes -notin (1,2)) {$MergedOrganizationTypes = Read-Host "Would you like to merge certain organization types in ITGlue to a given existing hudu company?.`n 1) Operate as normal`n 2) Scope ITGlue Org Type to a Company in Hudu`n(1/2)"}
switch ($MergedOrganizationTypes) {
"1" {$MergedOrganizationTypes = $false}
"2" {$MergedOrganizationTypes = $true}
}
# Choose if you would like to enable monitoring for the imported websites.
while ($DisableWebsiteMonitoring -notin (1,2)) {$DisableWebsiteMonitoring = Read-Host "1) Leave Website Monitoring enabled `n2) Disable Website Monitoring`n(1/2)"}
switch ($DisableWebsiteMonitoring) {
"1" {$DisableWebsiteMonitoring = $false}
"2" {$DisableWebsiteMonitoring = $true}
}
############################### Configuration Settings ###############################
while ($ImportConfigurations -notin (1,2)) {$ImportConfigurations = Read-Host "1) Import Configurations `n2) Skip Configurations`n(1/2)"}
switch ($ImportConfigurations) {
"1" {$ImportConfigurations = $true}
"2" {$ImportConfigurations = $false}
}
# The font awesome name for the locations icon in Hudu
$ConfigImportIcon = "fas fa-sitemap"
# Set if you would like a Prefix in front of configuration names created in Hudu. This can make it easy to review and you can rename them later set to ""if you dont want one
$ConfigurationPrefix = $environmentSettings.ConPromptPrefix
############################### Contact Settings ###############################
while ($ImportContacts -notin (1,2)) {$ImportContacts = Read-Host "1) Import Contacts `n2) Skip Contacts`n(1/2)"}
switch ($ImportContacts) {
"1" {$ImportContacts = $true}
"2" {$ImportContacts = $false}
}
# The asset layout name how locations will appear in Hudu
$ConImportAssetLayoutName = $ConImportAssetLayoutName ?? "People"
# The font awesome name for the locations icon in Hudu
$ConImportIcon = "fas fa-users"
############################### Flexible Asset Layouts ###############################
while ($ImportFlexibleAssetLayouts -notin (1,2)) {$ImportFlexibleAssetLayouts = Read-Host "1) Import Asset Layouts `n2) Skip Asset Layouts`n(1/2)"}
switch ($ImportFlexibleAssetLayouts) {
"1" {$ImportFlexibleAssetLayouts = $true}
"2" {$ImportFlexibleAssetLayouts = $false}
}
# Set if you would like a Prefix in front of Layout names created in Hudu. This can make it easy to review and you can rename them later set to ""if you don't want one
$FlexibleLayoutPrefix = $environmentSettings.FAPromptPrefix
############################### Flexible Assets ###############################
while ($ImportFlexibleAssets -notin (1,2)) {$ImportFlexibleAssets = Read-Host "1) Import Assets `n2) Skip Assets`n(1/2)"}
switch ($ImportFlexibleAssets) {
"1" {$ImportFlexibleAssets = $true}
"2" {$ImportFlexibleAssets = $false}
}
############################### Articles ###############################
while ($ImportArticles -notin (1,2)) {$ImportArticles = Read-Host "1) Import Articles `n2) Skip Articles`n(1/2)"}
switch ($ImportArticles) {
"1" {$ImportArticles = $true}
"2" {$ImportArticles = $false}
}
############################### Passwords ###############################
while ($ImportPasswords -notin (1,2)) {$ImportPasswords = Read-Host "1) Import Passwords `n2) Skip Passwords`n(1/2)"}
switch ($ImportPasswords) {
"1" {$ImportPasswords = $true}
"2" {$ImportPasswords = $false}
}
############################### Unattended ###############################
while ($NonInteractive -notin (1,2)) {$NonInteractive = Read-Host "1) Run normally `n2) Perform this migration noninteractively `n(1/2)"}
switch ($NonInteractive) {
"1" {$NonInteractive = $false}
"2" {$NonInteractive = $true}
}
############################### Scoping ###############################
while ($ScopedMigration -notin (1,2)) {$ScopedMigration = Read-Host "1) Run normally `n2) Perform migration scoped to certain companies `n(1/2)"}
switch ($ScopedMigration) {
"1" {$ScopedMigration = $false}
"2" {$ScopedMigration = $true}
}
############################## Checklists ##############################
while ($importChecklists -notin @(1,2, $true, $false)) {$importChecklists = Read-Host "Would you like to import Checklists? (requires web access to ITGlue).`n 1) No, Skip Checklists (Default)`n 2) Yes, Import Checklists (requires JWT, more difficult)`n(1/2)"}
switch ($importChecklists) {
"1" {$importChecklists = $false}
"2" {$importChecklists = $true}
}
############################ PasswordFolders ############################
while ($importPasswordFolders -notin @(1,2, $true, $false)) {$importPasswordFolders = Read-Host "Would you like to import Password Folders?`n 1) Yes`n 2) No, Skip Password Folders`n(1/2)"}
switch ($importPasswordFolders) {
"1" {$importPasswordFolders = $true;
$GlobalPasswordFolderMode = $GlobalPasswordFolderMode ?? $([bool]$("global" -eq $(Select-ObjectFromList -message "Password folder import mode-" -objects @("global","per-company"))))
$companyPasswordFolderAttributionMove = $companyPasswordFolderAttributionMove ?? $(if ($true -eq $GlobalPasswordFolderMode) {[bool]$("yes" -eq $(Select-ObjectFromList -message "Password Folders with only one company of passwords- do you want to move those to company-scope password folders? (if you aren't sure, 'yes' is generally a good bet)" -objects @("yes","no")))} else {$false})
}
"2" {$importPasswordFolders = $false; $GlobalPasswordFolderMode = $null; $companyPasswordFolderAttributionMove = $false}
}
############################## Interfaces ##############################
while ($ImportConfigInterfaces -notin @(1,2, $true, $false)) {$ImportConfigInterfaces = Read-Host "Would you like to import configuration interfaces (IP Addresses) into IPam in Hudu (requires more time)?.`n 1) Yes`n 2) No, Skip Interfaces/Addresses`n(1/2)"}
switch ($ImportConfigInterfaces) {
"1" {$ImportConfigInterfaces = $true}
"2" {$ImportConfigInterfaces = $false}
}
############################ Image Anchors Regex ############################
$OptionalImageAnchorReplace = $OptionalImageAnchorReplace ?? $true
while ($OptionalImageAnchorReplace -notin @(1,2, $true, $false)) {$OptionalImageAnchorReplace = Read-Host "[Other, default 1/$true] Would you like to replace links to hosted images in Hudu? (Not commonly needed but can be good for images-as-links in articles).`n 1) Yes`n 2) No, skip image-links`n(1/2)"}
switch ($OptionalImageAnchorReplace) {
"1" {$OptionalImageAnchorReplace = $true}
"2" {$OptionalImageAnchorReplace = $false}
}
while ($skipIntegratorLayouts -notin @(1,2, $true, $false)){
$skipIntegratorLayoutsInput = Read-Host "[Other, default false] Would you like to skip importing Integrator Layouts? These are often containing data that goes unused.`n 1) Yes`n 2) No, import all layouts`n(1/2)"
switch ($skipIntegratorLayoutsInput) {
"1" {$skipIntegratorLayouts = $true}
"2" {$skipIntegratorLayouts = $false}
}
}
$allowSettingFlagsAndTypes = $allowSettingFlagsAndTypes ?? $false
while ($allowSettingFlagsAndTypes -notin @(1,2, $true, $false)){
$allowSettingFlagsAndTypes = Read-Host "Would you like to apply flags and flag types during the migration? This requires Hudu version 2.40.0 or later.`n 1) Yes`n 2) No, skip setting Flags and FlagTypes`n(1/2)"
switch ($allowSettingFlagsAndTypes) {
"1" {$allowSettingFlagsAndTypes = $true}
"2" {$allowSettingFlagsAndTypes = $false}
}
$IncludeIgnoredFirstArticleDirectory = $IncludeIgnoredFirstArticleDirectory ?? [bool]((select-objectfromlist -message "would you like to include root directories when migrating article folders? default behavior is no/false" -objects @("no","yes")) -eq "yes")
}
}
############################ Migration Logs Path ##############################
$MigrationLogs = $environmentSettings.MigrationLogs
# Now that ITGlue export jobs require a user to elect to include passwords via checkbox, we need to check for the presence of the passwords.csv and warn user in relation to their migration strategy.
$passwordsCSVvalidated = $false
while ($passwordsCSVvalidated -eq $false) {
if (Test-Path -Path $(join-path -path $ITGLueExportPath -childpath "passwords.csv") -ErrorAction SilentlyContinue) {
Write-Host "Password CSV found at $(join-path -path $ITGLueExportPath -childpath "passwords.csv")" -ForegroundColor Cyan
$passwordsCSVvalidated = $true
} elseif ((2,$false) -contains $ImportPasswords -and (2,$false) -contains $ImportFlexibleAssets) {
write-host "passwords.csv not found at $(join-path -path $ITGLueExportPath -childpath "passwords.csv"), but since you have chosen to skip both flexible assets and passwords, this file is not needed specifically for your migration. If you later choose to migrate either of those sections, make sure to have a passwords.csv in your export folder." -ForegroundColor Yellow; start-sleep -seconds 2;
$passwordsCSVvalidated = $true
} else {
Write-Host "passwords.csv not found at $(join-path -path $ITGLueExportPath -childpath "passwords.csv"). You'll want to take another export, this time ensuring that passwords are included. Failure to do so will result in missing password data. Passwords.csv is used in both flexible assets and passwords portions of the migration." -ForegroundColor Red; start-sleep -seconds 2;
$overrideNoPassCSV = read-host "Press Enter to re-check for the file if you have extracted a new export to $($ITGLueExportPath), or Ctrl+C to exit. To continue anyway without passwords CSV (not reccomended), please enter this phrase exactly with no quotes: 'migrate-anyway'"
if ($overrideNoPassCSV -ieq 'migrate-anyway') {
Write-Host "Continuing without passwords.csv. Password data will be missing from the migration." -ForegroundColor Yellow
$passwordsCSVvalidated = $true
}
}
}
############################### End of Settings ###############################
############################## Load ImageMagick ###############################
# Import ImageMagick Modules, prompt for path if the module is missing
#Write-Host "Adding Imagemagick commands from dot NET assemblies" -ForegroundColor Cyan
#$ImageMagickPath = "$PSScriptRoot\Magick.NET-Q16-AnyCPU.dll"
<# while (!('ImageMagick.MagickImage'-as [type])) {
if (Test-Path "$ImageMagickPath") {
try {
Add-Type -Path $ImageMagickPath -ErrorAction Stop
}
catch {
throw "Failed to load ImageMagick, please check the files and try again. `n $_"
}
}
else {
$ImageMagickPath = (Read-Host "Failed to load ImageMagick. Please provide path for the three DLLs.") + "\Magick.NET-Q16-AnyCPU.dll"
}
} #>
################### Initialization Complete #############################