-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathITGlue-Hudu-Migration.ps1
2259 lines (1857 loc) · 108 KB
/
ITGlue-Hudu-Migration.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
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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Main settings load
. $PSScriptRoot\Initialize-Module.ps1 -InitType 'Full'
############################### Functions ###############################
# Import ImageMagick for Invoke-ImageTest Function (Disabled)
. $PSScriptRoot\Private\Initialize-ImageMagik.ps1
# Used to determine if a file is an image and what type of image
. $PSScriptRoot\Private\Invoke-ImageTest.ps1
# Confirm Object Import
. $PSScriptRoot\Private\Confirm-Import.ps1
# Matches items from IT Glue to Hudu and creates new items in Hudu
. $PSScriptRoot\Private\Import-Items.ps1
# Select Item Import Mode
. $PSScriptRoot\Private\Get-ImportMode.ps1
# Get Configurations Option
. $PSScriptRoot\Private\Get-ConfigurationsImportMode.ps1
# Get Flexible Asset Layout Option
. $PSScriptRoot\Private\Get-FlexLayoutImportMode.ps1
# Fetch Items from ITGlue
. $PSScriptRoot\Private\Import-ITGlueItems.ps1
# Find migrated items
. $PSScriptRoot\Private\Find-MigratedItem.ps1
# Lookup table to upgrade from Font Awesome 4 to 5
. $PSScriptRoot\Private\Get-FontAwesomeMap.ps1
$FontAwesomeUpgrade = Get-FontAwesomeMap
# Add Replace URL functions
. $PSScriptRoot\Private\ConvertTo-HuduURL.ps1
# Add Hudu Relations Function
. $PSScriptRoot\Public\Add-HuduRelation.ps1
############################### End of Functions ###############################
###################### Initial Setup and Confirmations ###############################
Write-Host "#######################################################" -ForegroundColor Green
Write-Host "# #" -ForegroundColor Green
Write-Host "# IT Glue to Hudu Migration Script #" -ForegroundColor Green
Write-Host "# #" -ForegroundColor Green
Write-Host "# Version: 2.0 -Beta #" -ForegroundColor Green
Write-Host "# Date: 02/07/2023 #" -ForegroundColor Green
Write-Host "# #" -ForegroundColor Green
Write-Host "# Author: Luke Whitelock #" -ForegroundColor Green
Write-Host "# https://mspp.io #" -ForegroundColor Green
Write-Host "# Contributors: John Duprey #" -ForegroundColor Green
Write-Host "# Mendy Green #" -ForegroundColor Green
Write-Host "# https://MSPGeek.org #" -ForegroundColor Green
Write-Host "# https://mendyonline.com #" -ForegroundColor Green
Write-Host "# #" -ForegroundColor Green
Write-Host "#######################################################" -ForegroundColor Green
Write-Host "# Note: This is an unofficial script, please do not #" -ForegroundColor Green
Write-Host "# contact Hudu support if you run into issues. #" -ForegroundColor Green
Write-Host "# For support please visit the Hudu Sub-Reddit: #" -ForegroundColor Green
Write-Host "# https://www.reddit.com/r/hudu/ #" -ForegroundColor Green
Write-Host "# The #v-hudu channel on the MSPGeek Slack/Discord: #" -ForegroundColor Green
Write-Host "# https://join.mspgeek.com/ #" -ForegroundColor Green
Write-Host "# Or log an issue in the Github Respository: #" -ForegroundColor Green
Write-Host "# https://github.com/lwhitelock/ITGlue-Hudu-Migration #" -ForegroundColor Green
Write-Host "#######################################################" -ForegroundColor Green
Write-Host " Instructions: " -ForegroundColor Green
Write-Host " Please view Luke's blog post: " -ForegroundColor Green
Write-Host " https://mspp.io/automated-it-glue-to-hudu-migration-script/ " -ForegroundColor Green
Write-Host " for detailed instructions " -ForegroundColor Green
Write-Host "#######################################################" -ForegroundColor Green
Write-Host "# Please keep ALL COPIES of the Migration Logs folder. This can save you." -ForegroundColor Gray
Write-Host "# Please DO NOT CHANGE ANYTHING in the Migration Logs folder. This can save you." -ForegroundColor Gray
# CMA
Write-Host "######################################################" -ForegroundColor Red
Write-Host "Have you taken a full backup of your Hudu Environment?" -ForegroundColor Red
Write-Host "Things could go wrong and you need to be able to " -ForegroundColor Red
Write-Host "recover to the state from before the script was run" -ForegroundColor Red
Write-Host "######################################################" -ForegroundColor Red
Write-Host "######################################################" -ForegroundColor Red
Write-Host "This Script has the potential to ruin your Hudu environment" -ForegroundColor Red
Write-Host "It is unofficial and you run it entirely at your own risk" -ForegroundColor Red
Write-Host "You accept full responsibility for any problems caused by running it" -ForegroundColor Red
Write-Host "######################################################" -ForegroundColor Red
$backups = Read-Host "Y/n"
$ScriptStartTime = $(Get-Date -Format "o")
if ($backups -ne "Y" -or $backups -ne "y") {
Write-Host "Please take a backup and run the script again"
exit 1
}
if ((get-host).version.major -ne 7) {
Write-Host "Powershell 7 Required" -foregroundcolor Red
exit 1
}
#Get the Hudu API Module if not installed
if ((Get-Module -ListAvailable -Name HuduAPI).version -ge '2.4.4') {
Import-Module HuduAPI
} else {
Install-Module HuduAPI -MinimumVersion 2.4.5 -Scope CurrentUser
Import-Module HuduAPI
}
#Login to Hudu
New-HuduAPIKey $HuduAPIKey
New-HuduBaseUrl $HuduBaseDomain
# Check we have the correct version
$RequiredHuduVersion = "2.1.5.9"
$HuduAppInfo = Get-HuduAppInfo
If ([version]$HuduAppInfo.version -lt [version]$RequiredHuduVersion) {
Write-Host "This script requires at least version $RequiredHuduVersion. Please update your version of Hudu and run the script again. Your version is $($HuduAppInfo.version)"
exit 1
}
try {
remove-module ITGlueAPI -ErrorAction SilentlyContinue
} catch {
}
#Grabbing ITGlue Module and installing.
If (Get-Module -ListAvailable -Name "ITGlueAPIv2") {
Import-module ITGlueAPIv2
} Else {
Install-Module ITGlueAPIv2 -Force
Import-Module ITGlueAPIv2
}
#Settings IT-Glue logon information
Add-ITGlueBaseURI -base_uri $ITGAPIEndpoint
Add-ITGlueAPIKey $ITGKey
# Check if we have a logs folder
if (Test-Path -Path "$MigrationLogs") {
if ($ResumePrevious -eq $true) {
Write-Host "A previous attempt has been found job will be resumed from the last successful section" -ForegroundColor Green
$ResumeFound = $true
} else {
Write-Host "A previous attempt has been found, resume is disabled so this will be lost, if you haven't reverted to a snapshot, a resume is recommended" -ForegroundColor Red
Read-Host "Press any key to continue or ctrl + c to quit and edit the ResumePrevious setting"
$ResumeFound = $false
}
} else {
Write-Host "No previous runs found creating log directory"
$null = New-Item "$MigrationLogs" -ItemType "directory"
$ResumeFound = $false
}
# Setup some variables
$ManualActions = [System.Collections.ArrayList]@()
############################### Companies ###############################
#Grab existing companies in Hudu
$HuduCompanies = Get-HuduCompanies
#Check for Company Resume
if ($ResumeFound -eq $true -and (Test-Path "$MigrationLogs\Companies.json")) {
Write-Host "Loading Previous Companies Migration"
$MatchedCompanies = Get-Content "$MigrationLogs\Companies.json" -raw | Out-String | ConvertFrom-Json
} else {
#Import Companies
Write-Host "Fetching Companies from IT Glue" -ForegroundColor Green
$CompanySelect = { (Get-ITGlueOrganizations -page_size 1000 -page_number $i).data }
$ITGCompanies = Import-ITGlueItems -ItemSelect $CompanySelect
$ITGCompaniesFromCSV = Import-CSV (Join-Path -Path $ITGlueExportPath -ChildPath "organizations.csv")
Write-Host "$($ITGCompanies.count) ITG Glue Companies Found"
$MatchedCompanies = foreach ($itgcompany in $ITGCompanies ) {
$HuduCompany = $HuduCompanies | where-object -filter { $_.name -eq $itgcompany.attributes.name }
if ($InternalCompany -eq $itgcompany.attributes.name) {
$intCompany = $true
} else {
$intCompany = $false
}
if ($HuduCompany) {
[PSCustomObject]@{
"CompanyName" = $itgcompany.attributes.name
"ITGID" = $itgcompany.id
"HuduID" = $HuduCompany.id
"Matched" = $true
"InternalCompany" = $intCompany
"HuduCompanyObject" = $HuduCompany
"ITGCompanyObject" = $itgcompany
"Imported" = "Pre-Existing"
}
} else {
[PSCustomObject]@{
"CompanyName" = $itgcompany.attributes.name
"ITGID" = $itgcompany.id
"HuduID" = ""
"Matched" = $false
"InternalCompany" = $intCompany
"HuduCompanyObject" = ""
"ITGCompanyObject" = $itgcompany
"Imported" = ""
}
}
}
# Check if the internal company was found and that there was only 1 of them
$PrimaryCompany = $MatchedCompanies | Sort-Object CompanyName | Where-Object { $_.InternalCompany -eq $true } | Select-Object CompanyName
if (($PrimaryCompany | measure-object).count -ne 1) {
Write-Host "A single Internal Company was not found please run the script again and check the company name entered exactly matches what is in ITGlue" -foregroundcolor red
exit 1
}
# Lets confirm it is the correct one
Write-Host ""
Write-Host "Your Internal Company has been matched to: $(($MatchedCompanies | Sort-Object CompanyName | Where-Object {$_.InternalCompany -eq $true} | Select-Object CompanyName).companyname) in IT Glue"
Write-Host "The documents under this customer will be migrated to the Global KB in Hudu"
Write-Host ""
Read-Host -Prompt "Press Return to continue or CTRL+C to quit if this is not correct"
Write-Host "Matched Companies (Already exist so will not be migrated)"
$MatchedCompanies | Sort-Object CompanyName | Where-Object { $_.Matched -eq $true } | Select-Object CompanyName | Format-Table
Write-Host "Unmatched Companies"
$MatchedCompanies | Sort-Object CompanyName | Where-Object { $_.Matched -eq $false } | Select-Object CompanyName | Format-Table
#Import Locations
Write-Host "Fetching Locations from IT Glue" -ForegroundColor Green
$LocationsSelect = { (Get-ITGlueLocations -page_size 1000 -page_number $i -include related_items).data }
$ITGLocations = Import-ITGlueItems -ItemSelect $LocationsSelect
# Import Companies
$UnmappedCompanyCount = ($MatchedCompanies | Where-Object { $_.Matched -eq $false } | measure-object).count
if ($ImportCompanies -eq $true -and $UnmappedCompanyCount -gt 0) {
$importCOption = Get-ImportMode -ImportName "Companies"
if (($importCOption -eq "A") -or ($importCOption -eq "S") ) {
foreach ($unmatchedcompany in ($MatchedCompanies | Where-Object { $_.Matched -eq $false })) {
$unmatchedcompany.ITGCompanyObject.attributes.'quick-notes' = ($ITGCompaniesFromCSV | Where-Object {$_.id -eq $unmatchedcompany.ITGID}).quick_notes
$unmatchedcompany.ITGCompanyObject.attributes.alert = ($ITGCompaniesFromCSV | Where-Object {$_.id -eq $unmatchedcompany.ITGID}).alert
Confirm-Import -ImportObjectName $unmatchedcompany.CompanyName -ImportObject $unmatchedcompany -ImportSetting $importCOption
Write-Host "Starting $($unmatchedcompany.CompanyName)"
$PrimaryLocation = $ITGLocations | Where-Object { $unmatchedcompany.ITGID -eq $_.attributes."organization-id" -and $_.attributes.primary -eq $true }
#Check for alerts in ITGlue on the organization
if ($ITGlueAlert = $unmatchedcompany.ITGCompanyObject.attributes.alert) {
$CompanyNotes = "<div class='callout callout-warning'>$ITGlueAlert</div>" + $unmatchedcompany.ITGCompanyObject.attributes."quick-notes"
} else {
$CompanyNotes = $unmatchedcompany.ITGCompanyObject.attributes."quick-notes"
}
if ($PrimaryLocation -and $PrimaryLocation.count -eq 1) {
$CompanySplat = @{
"name" = $unmatchedcompany.CompanyName
"nickname" = $unmatchedcompany.ITGCompanyObject.attributes."short-name"
"address_line_1" = $PrimaryLocation.attributes."address-1"
"address_line_2" = $PrimaryLocation.attributes."address-2"
"city" = $PrimaryLocation.attributes.city
"state" = $PrimaryLocation.attributes."region-name"
"zip" = $PrimaryLocation.attributes."postal-code"
"country_name" = $PrimaryLocation.attributes."country-name"
"phone_number" = $PrimaryLocation.attributes.phone
"fax_number" = $PrimaryLocation.attributes.fax
"notes" = $CompanyNotes
"CompanyType" = $unmatchedcompany.ITGCompanyObject.attributes.'organization-type-name'
}
$HuduNewCompany = (New-HuduCompany @CompanySplat).company
$CompaniesMigrated = $CompaniesMigrated + 1
} else {
Write-Host "No Location Found, creating company without address details"
$HuduNewCompany = (New-HuduCompany -name $unmatchedcompany.CompanyName -nickname $unmatchedcompany.ITGCompanyObject.attributes."short-name" -notes $CompanyNotes -CompanyType $unmatchedcompany.attributes.'organization-type-name').company
$CompaniesMigrated = $CompaniesMigrated + 1
}
$unmatchedcompany.matched = $true
$unmatchedcompany.HuduID = $HuduNewCompany.id
$unmatchedcompany.HuduCompanyObject = $HuduNewCompany
$unmatchedcompany.Imported = "Created-By-Script"
Write-host "$($unmatchedcompany.CompanyName) Has been created in Hudu"
Write-Host ""
}
}
} else {
if ($UnmappedCompanyCount -eq 0) {
Write-Host "All Companies matched, no migration required" -foregroundcolor green
} else {
Write-Host "Warning Import Companies is set to disabled so the above unmatched companies will not have data migrated" -foregroundcolor red
Read-Host -Prompt "Press any key to continue or CTRL+C to quit"
}
}
# Save the results to resume from if needed
$MatchedCompanies | ConvertTo-Json -depth 100 | Out-File "$MigrationLogs\Companies.json"
Read-Host "Snapshot Point: Companies Migrated Continue?"
}
$CompaniesToMigrate = $MatchedCompanies | Sort-Object CompanyName | Where-Object { $_.Matched -eq $true }
$HuduCompanies = Get-HuduCompanies
############################### Locations ###############################
#Check for Location Resume
if ($ResumeFound -eq $true -and (Test-Path "$MigrationLogs\Locations.json")) {
Write-Host "Loading Previous Locations Migration"
$MatchedLocations = Get-Content "$MigrationLogs\Locations.json" -raw | Out-String | ConvertFrom-Json -depth 100
} else {
$LocHuduItemFilter = { ($_.name -eq $itgimport.attributes.name -and $_.company_name -eq $itgimport.attributes."organization-name")`
-or ($ITGPrimaryLocationNames -contains $itgimport.attributes.name -and $HuduPrimaryLocationNames -contains $_.name -and $_.company_name -eq $itgimport.attributes."organization-name")`
-or ($itgimport.attributes.primary -eq $true -and $HuduPrimaryLocationNames -contains $_.name -and $_.company_name -eq $itgimport.attributes."organization-name") }
$LocImportEnabled = $ImportLocations
$LocMigrationName = "Locations"
$LocAssetLayoutFields = @(
@{
label = 'Address 1'
field_type = 'Text'
show_in_list = 'true'
position = 1
},
@{
label = 'Address 2'
field_type = 'Text'
show_in_list = 'false'
position = 2
},
@{
label = 'City'
field_type = 'Text'
show_in_list = 'true'
position = 3
},
@{
label = 'Postal Code'
field_type = 'Text'
show_in_list = 'true'
position = 4
},
@{
label = 'Region'
field_type = 'Text'
show_in_list = 'false'
position = 5
},
@{
label = 'Country'
field_type = 'Text'
show_in_list = 'false'
position = 6
},
@{
label = 'Phone'
field_type = 'Text'
show_in_list = 'false'
position = 7
},
@{
label = 'Fax'
field_type = 'Text'
show_in_list = 'false'
position = 8
},
@{
label = 'Notes'
field_type = 'RichText'
show_in_list = 'false'
position = 9
}
)
$LocAssetFieldsMap = { @{
'address_1' = $unmatchedImport."ITGObject".attributes."address-1"
'address_2' = $unmatchedImport."ITGObject".attributes."address-2"
'city' = $unmatchedImport."ITGObject".attributes."city"
'postal_code' = $unmatchedImport."ITGObject".attributes."postal-code"
'region' = $unmatchedImport."ITGObject".attributes."region-name"
'country' = $unmatchedImport."ITGObject".attributes."country-name"
'phone' = $unmatchedImport."ITGObject".attributes."phone"
'fax' = $unmatchedImport."ITGObject".attributes."fax"
'notes' = $unmatchedImport."ITGObject".attributes."notes"
} }
$LocImportSplat = @{
AssetFieldsMap = $LocAssetFieldsMap
AssetLayoutFields = $LocAssetLayoutFields
ImportIcon = $LocImportIcon
ImportEnabled = $LocImportEnabled
HuduItemFilter = $LocHuduItemFilter
ImportAssetLayoutName = $LocImportAssetLayoutName
ItemSelect = $LocItemSelect
MigrationName = $LocMigrationName
ITGImports = $ITGLocations
}
#Import Locations
$MatchedLocations = Import-Items @LocImportSplat
# Save the results to resume from if needed
$MatchedLocations | ConvertTo-Json -depth 100 | Out-File "$MigrationLogs\Locations.json"
Read-Host "Snapshot Point: Locations Migrated Continue?"
}
############################### Websites ###############################
#Check for Website Resume
if ($ResumeFound -eq $true -and (Test-Path "$MigrationLogs\Websites.json")) {
Write-Host "Loading Previous Websites Migration"
$MatchedWebsites = Get-Content "$MigrationLogs\Websites.json" -raw | Out-String | ConvertFrom-Json
} else {
#Grab existing Websites in Hudu
$HuduWebsites = Get-HuduWebsites
#Import Websites
Write-Host "Fetching Domains from IT Glue" -ForegroundColor Green
$DomainSelect = { (Get-ITGlueDomains -page_size 1000 -page_number $i).data }
$ITGDomains = Import-ITGlueItems -ItemSelect $DomainSelect
Write-Host "$($ITGDomains.count) ITG Glue Domains Found"
$MatchedWebsites = foreach ($itgdomain in $ITGDomains ) {
$HuduWebsite = $HuduWebsites | where-object -filter { ($_.name -eq "https://$($itgdomain.attributes.name)" -and $_.company_name -eq $itgdomain.attributes."organization-name") }
if ($HuduWebsite) {
[PSCustomObject]@{
"Name" = $itgdomain.attributes.name
"ITGID" = $itgdomain.id
"HuduID" = $HuduWebsite.id
"Matched" = $true
"HuduObject" = $HuduWebsite
"ITGObject" = $itgdomain
"Imported" = "Pre-Existing"
}
} else {
[PSCustomObject]@{
"Name" = $itgdomain.attributes.name
"ITGID" = $itgdomain.id
"HuduID" = ""
"Matched" = $false
"HuduObject" = ""
"ITGObject" = $itgdomain
"Imported" = ""
}
}
}
Write-Host "Matched Websites / Domains (Already exist so will not be migrated)"
$MatchedWebsites | Sort-Object Name | Where-Object { $_.Matched -eq $true } | Select-Object Name | Format-Table
Write-Host "Unmatched Websites / Domains"
$MatchedWebsites | Sort-Object Name | Where-Object { $_.Matched -eq $false } | Select-Object Name | Format-Table
$UnmappedWebsiteCount = ($MatchedWebsites | Where-Object { $_.Matched -eq $false } | measure-object).count
if ($ImportDomains -eq $true -and $UnmappedWebsiteCount -gt 0) {
$importOption = Get-ImportMode -ImportName "Websites / Domains"
if (($importOption -eq "A") -or ($importOption -eq "S") ) {
foreach ($company in $CompaniesToMigrate) {
Write-Host "Migrating $($company.CompanyName)" -ForegroundColor Green
foreach ($unmatchedWebsite in ($MatchedWebsites | Where-Object { $_.Matched -eq $false -and $company.ITGCompanyObject.id -eq $_."ITGObject".attributes."organization-id" })) {
Confirm-Import -ImportObjectName "$($unmatchedWebsite.Name)" -ImportObject $unmatchedWebsite -ImportSetting $ImportOption
Write-Host "Starting $($unmatchedWebsite.Name)"
$HuduNewWebsite = New-HuduWebsite -name "https://$($unmatchedWebsite.ITGObject.attributes.name)" -notes $unmatchedWebsite.ITGObject.attributes.notes -paused $DisableWebsiteMonitoring -companyid $company.HuduCompanyObject.ID -disabledns $DisableWebsiteMonitoring -disablessl $DisableWebsiteMonitoring -disablewhois $DisableWebsiteMonitoring
$unmatchedWebsite.matched = $true
$unmatchedWebsite.HuduID = $HuduNewWebsite.id
$unmatchedWebsite."HuduObject" = $HuduNewWebsite
$unmatchedWebsite.Imported = "Created-By-Script"
$ImportsMigrated = $ImportsMigrated + 1
Write-host "$($unmatchedWebsite.Name) Has been created in Hudu"
}
}
}
} else {
if ($UnmappedWebsiteCount -eq 0) {
Write-Host "All $MigrationName matched, no migration required" -foregroundcolor green
} else {
Write-Host "Warning Import Websites is set to disabled so the above unmatched Websites will not have data migrated" -foregroundcolor red
Read-Host -Prompt "Press any key to continue or CTRL+C to quit"
}
}
# Save the results to resume from if needed
$MatchedWebsites | ConvertTo-Json -depth 100 | Out-File "$MigrationLogs\Websites.json"
Read-Host "Snapshot Point: Websites Migrated Continue?"
}
############################### Configurations ###############################
$ConfigMigrationName = "Configurations"
$ConfigImportAssetLayoutName = "Configurations"
#Check for Configuration Resume
if ($ResumeFound -eq $true -and (Test-Path "$MigrationLogs\Configurations.json")) {
Write-Host "Loading Previous Configurations Migration"
$MatchedConfigurations = Get-Content "$MigrationLogs\Configurations.json" -raw | Out-String | ConvertFrom-Json -depth 100
} else {
#Get Configurations from IT Glue
Write-Host "Fetching Configurations from IT Glue" -ForegroundColor Green
$ConfigurationsSelect = { (Get-ITGlueConfigurations -page_size 1000 -page_number $i -include related_items).data }
$ITGConfigurations = Import-ITGlueItems -ItemSelect $ConfigurationsSelect
$ConfigAssetLayoutFields = @(
@{
label = 'Hostname'
field_type = 'Text'
show_in_list = 'true'
position = 1
},
@{
label = 'Primary IP'
field_type = 'Text'
show_in_list = 'false'
position = 2
},
@{
label = 'MAC Address'
field_type = 'Text'
show_in_list = 'true'
position = 3
},
@{
label = 'Default Gateway'
field_type = 'Text'
show_in_list = 'true'
position = 4
},
@{
label = 'Serial Number'
field_type = 'Text'
show_in_list = 'false'
position = 5
},
@{
label = 'Asset Tag'
field_type = 'Text'
show_in_list = 'false'
position = 6
},
@{
label = 'Position'
field_type = 'Text'
show_in_list = 'false'
position = 7
},
@{
label = 'Installed By'
field_type = 'Text'
show_in_list = 'false'
position = 8
},
@{
label = 'Purchased By'
field_type = 'Text'
show_in_list = 'false'
position = 9
},
@{
label = 'Notes'
field_type = 'RichText'
show_in_list = 'false'
position = 10
},
@{
label = 'Operating System Notes'
field_type = 'RichText'
show_in_list = 'false'
position = 11
},
@{
label = 'Warranty Expires At'
field_type = 'Date'
expiration = 'true'
show_in_list = 'false'
position = 12
},
@{
label = 'Installed At'
field_type = 'Date'
show_in_list = 'false'
position = 13
},
@{
label = 'Purchased At'
field_type = 'Date'
show_in_list = 'false'
position = 14
},
@{
label = 'Configuration Type Name'
field_type = 'Text'
show_in_list = 'false'
position = 15
},
@{
label = 'Configuration Type Kind'
field_type = 'Text'
show_in_list = 'false'
position = 16
},
@{
label = 'Configuration Status Name'
field_type = 'Text'
show_in_list = 'false'
position = 17
},
@{
label = 'Manufacturer Name'
field_type = 'Text'
show_in_list = 'false'
position = 18
},
@{
label = 'Model ID'
field_type = 'Text'
show_in_list = 'false'
position = 19
},
@{
label = 'Operating System Name'
field_type = 'Text'
show_in_list = 'false'
position = 20
},
@{
label = 'Location Name'
field_type = 'Text'
show_in_list = 'false'
position = 21
},
@{
label = 'Model Name'
field_type = 'Text'
show_in_list = 'false'
position = 22
},
@{
label = 'Contact Name'
field_type = 'Text'
show_in_list = 'false'
position = 23
}
)
$ConfigHuduItemFilter = { ($_.name -eq $itgimport.attributes.name -and $_.company_name -eq $itgimport.attributes."organization-name") }
$ConfigImportEnabled = $ImportConfigurations
$ConfigAssetFieldsMap = { @{
'name' = $unmatchedImport."ITGObject".attributes."name"
'hostname' = $unmatchedImport."ITGObject".attributes."hostname"
'primary_ip' = $unmatchedImport."ITGObject".attributes."primary-ip"
'mac_address' = $unmatchedImport."ITGObject".attributes."mac-address"
'default_gateway' = $unmatchedImport."ITGObject".attributes."default-gateway"
'serial_number' = $unmatchedImport."ITGObject".attributes."serial-number"
'asset_tag' = $unmatchedImport."ITGObject".attributes."asset-tag"
'position' = $unmatchedImport."ITGObject".attributes."position"
'installed_by' = $unmatchedImport."ITGObject".attributes."installed-by"
'purchased_by' = $unmatchedImport."ITGObject".attributes."purchased-by"
'notes' = $unmatchedImport."ITGObject".attributes."notes"
'operating_system_notes' = $unmatchedImport."ITGObject".attributes."operating-system-notes"
'warranty_expires_at' = $unmatchedImport."ITGObject".attributes."warranty-expires-at"
'installed_at' = $unmatchedImport."ITGObject".attributes."installed-at"
'purchased_at' = $unmatchedImport."ITGObject".attributes."purchased-at"
'created_at' = $unmatchedImport."ITGObject".attributes."created-at"
'updated_at' = $unmatchedImport."ITGObject".attributes."updated-at"
'configuration_type_name' = $unmatchedImport."ITGObject".attributes."configuration-type-name"
'configuration_type_kind' = $unmatchedImport."ITGObject".attributes."configuration-type-kind"
'configuration_status_name' = $unmatchedImport."ITGObject".attributes."configuration-status-name"
'operating_system_name' = $unmatchedImport."ITGObject".attributes."operating-system-name"
'location_name' = $unmatchedImport."ITGObject".attributes."location-name"
'model_name' = $unmatchedImport."ITGObject".attributes."model-name"
'contact_name' = $unmatchedImport."ITGObject".attributes."contact-name"
} }
# First we need to decide on if we are going to do one Asset type or many
Write-Host "Hudu does not have the same standard configuration type as IT Glue."
Write-Host "With the migration there are a few options of how to approach this"
Write-Host "1) The script can create a new Hudu Asset Layout for all configurations to go into, like how IT Glue works"
Write-Host "2) The script can create an Asset layout for each in use Configuration Type you have in IT Glue and then split up configurations into them"
Write-Host "3) The script can prompt for each Configuration type you have, asking you for the new Hudu Asset Layout to map to, this will allow you to have a mix of 1 and 2"
$ConfigurationOption = Get-ConfigurationsImportMode
# All Configurations to 1 Layout
if ($ConfigurationOption -eq 1) {
$ConfigImportSplat = @{
AssetFieldsMap = $ConfigAssetFieldsMap
AssetLayoutFields = $ConfigAssetLayoutFields
ImportIcon = $ConfigImportIcon
ImportEnabled = $ConfigImportEnabled
HuduItemFilter = $ConfigHuduItemFilter
ImportAssetLayoutName = $ConfigImportAssetLayoutName
ItemSelect = $ConfigItemSelect
MigrationName = $ConfigMigrationName
ITGImports = $ITGConfigurations
}
$MatchedConfigurations = Import-Items @ConfigImportSplat
} elseif ($ConfigurationOption -eq 2) {
$ITGConfigTypes = $ITGConfigurations.attributes."configuration-type-name" | Select-Object -unique
$MatchedConfigurations = New-Object System.Collections.ArrayList
foreach ($ConfigType in $ITGConfigTypes) {
Write-Host "Processing $ConfigType"
$ParsedITGConfigs = $ITGConfigurations | Where-Object -filter { $_.attributes."configuration-type-name" -eq $ConfigType }
$ConfigMigrationName = "$($ConfigurationPrefix)$($ConfigType)"
$ConfigImportAssetLayoutName = "$($ConfigurationPrefix)$($ConfigType)"
$ConfigImportSplat = @{
AssetFieldsMap = $ConfigAssetFieldsMap
AssetLayoutFields = $ConfigAssetLayoutFields
ImportIcon = $ConfigImportIcon
ImportEnabled = $ConfigImportEnabled
HuduItemFilter = $ConfigHuduItemFilter
ImportAssetLayoutName = $ConfigImportAssetLayoutName
ItemSelect = $ConfigItemSelect
MigrationName = $ConfigMigrationName
ITGImports = $ParsedITGConfigs
}
$ReturnedConfigurations = Import-Items @ConfigImportSplat
if (($ReturnedConfigurations | measure-object).count -gt 1) {
$MatchedConfigurations.addrange($ReturnedConfigurations)
} else {
$MatchedConfigurations.add($ReturnedConfigurations)
}
}
} elseif ($ConfigurationOption -eq 3) {
$ITGConfigTypes = $ITGConfigurations.attributes."configuration-type-name" | Select-Object -unique
$MatchedConfigurations = New-Object System.Collections.ArrayList
foreach ($ConfigType in $ITGConfigTypes) {
Write-Host ""
Write-Host "Processing $ConfigType"
Write-Host "Please provide the Asset Layout name for $ConfigType in Hudu." -foregroundcolor green
$ConfigImportAssetLayoutName = Read-Host "Please enter layout name"
$ParsedITGConfigs = $ITGConfigurations | Where-Object -filter { $_.attributes."configuration-type-name" -eq $ConfigType }
$ConfigMigrationName = $ConfigImportAssetLayoutName
$ConfigImportSplat = @{
AssetFieldsMap = $ConfigAssetFieldsMap
AssetLayoutFields = $ConfigAssetLayoutFields
ImportIcon = $ConfigImportIcon
ImportEnabled = $ConfigImportEnabled
HuduItemFilter = $ConfigHuduItemFilter
ImportAssetLayoutName = $ConfigImportAssetLayoutName
ItemSelect = $ConfigItemSelect
MigrationName = $ConfigMigrationName
ITGImports = $ParsedITGConfigs
}
$ReturnedConfigurations = Import-Items @ConfigImportSplat
if (($ReturnedConfigurations | measure-object).count -gt 1) {
$MatchedConfigurations.addrange($ReturnedConfigurations)
} else {
$MatchedConfigurations.add($ReturnedConfigurations)
}
}
} else {
Write-Error "This should never have happened some how you selected something other than 1, 2 or 3 :/"
exit 1
}
# Save the results to resume from if needed
$MatchedConfigurations | ConvertTo-Json -depth 100 | Out-File "$MigrationLogs\Configurations.json"
Read-Host "Snapshot Point: Configurations Migrated Continue?"
}
############################### Contacts ###############################
#Check for Location Resume
if ($ResumeFound -eq $true -and (Test-Path "$MigrationLogs\Contacts.json")) {
Write-Host "Loading Previous Contacts Migration"
$MatchedContacts = Get-Content "$MigrationLogs\Contacts.json" -raw | Out-String | ConvertFrom-Json -depth 100
} else {
Write-Host "Fetching Contacts from IT Glue" -ForegroundColor Green
$ContactsSelect = { (Get-ITGlueContacts -page_size 1000 -page_number $i -include related_items).data }
$ITGContacts = Import-ITGlueItems -ItemSelect $ContactsSelect
#($ITGContacts.attributes | sort-object -property name, "organization-name" -Unique)
$ConHuduItemFilter = { ($_.name -eq $itgimport.attributes.name -and $_.company_name -eq $itgimport.attributes."organization-name") }
$ConImportEnabled = $ImportContacts
$ConMigrationName = "Contacts"
$LocationLayout = Get-HuduAssetLayouts -name $LocImportAssetLayoutName
$ConAssetLayoutFields = @(
@{
label = 'First Name'
field_type = 'Text'
show_in_list = 'true'
position = 1
},
@{
label = 'Last Name'
field_type = 'Text'
show_in_list = 'false'
position = 2
},
@{
label = 'Title'
field_type = 'Text'
show_in_list = 'true'
position = 3
},
@{
label = 'Contact Type'
field_type = 'Text'
show_in_list = 'true'
position = 4
},
@{
label = 'Location'
field_type = 'AssetTag'
show_in_list = 'false'
linkable_id = $LocationLayout.ID
position = 5
},
@{
label = 'Important'
field_type = 'Text'
show_in_list = 'false'
position = 6
},
@{
label = 'Notes'
field_type = 'RichText'
show_in_list = 'false'
position = 7
},
@{
label = 'Emails'
field_type = 'RichText'
show_in_list = 'false'
position = 8
},
@{
label = 'Phones'
field_type = 'RichText'
show_in_list = 'false'
position = 9
}
)
$ConAssetFieldsMap = { @{
'first_name' = $unmatchedImport."ITGObject".attributes."first-name"
'last_name' = $unmatchedImport."ITGObject".attributes."last-name"
'title' = $unmatchedImport."ITGObject".attributes."title"
'contact_type' = $unmatchedImport."ITGObject".attributes."contact-type-name"
'location' = "[$($MatchedLocations | where-object -filter {$_.ITGID -eq $unmatchedImport."ITGObject".attributes."location-id"} | Select-Object @{N='id';E={$_.HuduID}}, @{N='name';E={$_.Name}} | convertto-json -compress | out-string)]" -replace "`r`n", ""
'important' = $unmatchedImport."ITGObject".attributes."important"
'notes' = $unmatchedImport."ITGObject".attributes."notes"
'emails' = $unmatchedImport."ITGObject".attributes."contact-emails" | convertto-html -fragment | out-string
'phones' = $unmatchedImport."ITGObject".attributes."contact-phones" | convertto-html -fragment | out-string
} }
$ConImportSplat = @{
AssetFieldsMap = $ConAssetFieldsMap
AssetLayoutFields = $ConAssetLayoutFields
ImportIcon = $ConImportIcon
ImportEnabled = $ConImportEnabled
HuduItemFilter = $ConHuduItemFilter
ImportAssetLayoutName = $ConImportAssetLayoutName
ItemSelect = $ConItemSelect
MigrationName = $ConMigrationName
ITGImports = $ITGContacts
}
#Import Locations
$MatchedContacts = Import-Items @ConImportSplat
Write-Host "Contacts Complete"
# Save the results to resume from if needed
$MatchedContacts | ConvertTo-Json -depth 100 | Out-File "$MigrationLogs\Contacts.json"
Read-Host "Snapshot Point: Contacts Migrated Continue?"
}
############################### Flexible Asset Layouts and Assets ###############################
#Check for Layouts Resume
if ($ResumeFound -eq $true -and (Test-Path "$MigrationLogs\AssetLayouts.json")) {
Write-Host "Loading Previous Asset Layouts Migration"
$MatchedLayouts = Get-Content "$MigrationLogs\AssetLayouts.json" -raw | Out-String | ConvertFrom-Json -depth 100
$AllFields = Get-Content "$MigrationLogs\AssetLayoutsFields.json" -raw | Out-String | ConvertFrom-Json -depth 100
} else {
$ConfigImportAssetLayoutName = ($MatchedConfigurations.HuduObject | Select-Object name, asset_type | group-object -property asset_type | sort-object count -descending | Select-Object -first 1).name
Write-Host "Fetching Flexible Asset Layouts from IT Glue" -ForegroundColor Green
$FlexLayoutSelect = { (Get-ITGlueFlexibleAssetTypes -page_size 1000 -page_number $i -include related_items).data }
$FlexLayouts = Import-ITGlueItems -ItemSelect $FlexLayoutSelect
$HuduLayouts = Get-HuduAssetLayouts
Write-Host "The script will now migrate IT Glue Flexible Asset Layouts to Hudu"
Write-Host "Please select the option you would like"
Write-Host "1) Move all Flexible Asset Layouts to Hudu"
Write-Host "2) Determine on a layout by layout basis if you want to migrate"
$ImportOption = Get-FlexLayoutImportMode
$AllFields = [System.Collections.ArrayList]@()
# Match to existing layouts
$MatchedLayouts = foreach ($ITGLayout in $FlexLayouts) {
$HuduLayout = $HuduLayouts | where-object -filter { $_.name -eq "$($FlexibleLayoutPrefix)$($ITGLayout.attributes.name)" }
if ($HuduLayout) {
[PSCustomObject]@{
"Name" = $ITGLayout.attributes.name
"ITGID" = $ITGLayout.id
"HuduID" = $HuduLayout.id
"Matched" = $true
"HuduObject" = $HuduLayout
"ITGObject" = $ITGLayout