search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Virtual Machine Manager, Windows Powershell | 5 Comments | 7,047 views | 29/01/2014 17:44

SCVMM 2012 SP1 to SCVMM 2012 R2 Migration Script is updated!

Note: Please use v1.5 for migrations. Tested over 5000 objects without problem! Works great! :)

You may have many reasons to get your config backup of SCVMM instead of database backup. For example, your SCVMM database may be in inconsistent state and Microsoft may recommend you a reinstall of SCVMM with a new database. So in that case, you can use this script to backup your old SCVMM 2012 SP1 environment and restore to new SCVMM server.

This script is in v1.5. Backups and restores host groups, logical networks, logical network definitions, static ip address pools, clouds, user roles, user role quotas, user role permissions, host network adapters, vm templates and VM properties. There will be no update on this script anymore. If you want to add extra config, please update GitHub project.

GitHub: https://github.com/yusufozturk/scvmm

First backup your SCVMM:

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
# Backup Host Groups
$HostGroups = Get-SCVMHostGroup | ConvertTo-Json
$HostGroups | Set-Content -Path HostGroups.txt
 
# Backup Logical Networks
$LogicalNetworks = Get-SCLogicalNetwork | ConvertTo-Json
$LogicalNetworks | Set-Content -Path LogicalNetworks.txt
 
# Backup Logical Network Definitions
$LogicalNetworkDefinitions = Get-SCLogicalNetworkDefinition | ConvertTo-Json
$LogicalNetworkDefinitions | Set-Content -Path LogicalNetworkDefinitions.txt
 
# Backup Static IP Address Pools
$StaticIPAddressPools = Get-SCStaticIPAddressPool | ConvertTo-Json
$StaticIPAddressPools | Set-Content -Path StaticIPAddressPools.txt
 
# Backup VM Networks
$VMNetworks = Get-SCVMNetwork | ConvertTo-Json
$VMNetworks | Set-Content -Path VMNetworks.txt
 
# Backup VM Subnets
$VMSubnets = Get-SCVMSubnet | ConvertTo-Json
$VMSubnets | Set-Content -Path VMSubnets.txt
 
# Backup Clouds
$Clouds = Get-SCCloud | ConvertTo-Json
$Clouds | Set-Content -Path Clouds.txt
 
# Backup Library Shares
$LibraryShares = Get-SCLibraryShare | ConvertTo-Json
$LibraryShares | Set-Content -Path LibraryShares.txt
 
# Backup User Roles
$UserRoles = Get-SCUserRole | ConvertTo-Json -Depth 3
$UserRoles | Set-Content -Path UserRoles.txt
 
# Backup User Role Quotas
$UserRoleQuotas = Get-SCUserRoleQuota | ConvertTo-Json
$UserRoleQuotas | Set-Content -Path UserRoleQuotas.txt
 
# Backup VM Templates
$VMTemplates = Get-SCVMTemplate | ConvertTo-Json -Depth 3
$VMTemplates | Set-Content -Path VMTemplates.txt
 
# Backup Host Network Adapters
$HostNetworkAdapters = Get-SCVMHostNetworkAdapter | ConvertTo-Json -Depth 1
$HostNetworkAdapters | Set-Content -Path HostNetworkAdapters.txt
 
# Backup Virtual Machine Information
$VirtualMachines = Get-VM | ConvertTo-Json
$VirtualMachines | Set-Content -Path VirtualMachines.txt

You will see config backups under C drive. Transfer them to new SCVMM server.
You can restore all data with following script:

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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
# Load JSon Serialization
$LoadJson = [System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
$JsonSerial= New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer
$JsonSerial.MaxJsonLength = [int]::MaxValue
 
# Restore Host Groups
$HostGroupsRaw = Get-Content -Path HostGroups.txt -Raw
$HostGroups = $JsonSerial.DeserializeObject($HostGroupsRaw)
$HostGroups = $HostGroups | Sort-Object -Property ParentHostGroup.Path
 
# Restore Logical Network
$LogicalNetworksRaw = Get-Content -Path LogicalNetworks.txt -Raw
$LogicalNetworks = $JsonSerial.DeserializeObject($LogicalNetworksRaw)
 
# Restore Logical Network Definition
$LogicalNetworkDefinitionsRaw = Get-Content -Path LogicalNetworkDefinitions.txt -Raw
$LogicalNetworkDefinitions = $JsonSerial.DeserializeObject($LogicalNetworkDefinitionsRaw)
 
# Restore Static IP Address Pool
$StaticIPAddressPoolsRaw = Get-Content -Path StaticIPAddressPools.txt -Raw
$StaticIPAddressPools = $JsonSerial.DeserializeObject($StaticIPAddressPoolsRaw)
 
# Restore VM Networks
$VMNetworksRaw = Get-Content -Path VMNetworks.txt -Raw
$VMNetworks = $JsonSerial.DeserializeObject($VMNetworksRaw)
 
# Restore VM Subnets
$VMSubnetsRaw = Get-Content -Path VMSubnets.txt -Raw
$VMSubnets = $JsonSerial.DeserializeObject($VMSubnetsRaw)
 
# Restore Clouds
$CloudsRaw = Get-Content -Path Clouds.txt -Raw
$Clouds = $JsonSerial.DeserializeObject($CloudsRaw)
 
# Restore Library Shares
$LibrarySharesRaw = Get-Content -Path LibraryShares.txt -Raw
$LibraryShares = $JsonSerial.DeserializeObject($LibrarySharesRaw)
 
# Restore User Roles
$UserRolesRaw = Get-Content -Path UserRoles.txt -Raw
$UserRoles = $JsonSerial.DeserializeObject($UserRolesRaw)
 
# Restore User Role Quotas
$UserRoleQuotasRaw = Get-Content -Path UserRoleQuotas.txt -Raw
$UserRoleQuotas = $JsonSerial.DeserializeObject($UserRoleQuotasRaw)
 
# Restore VM Templates
$VMTemplatesRaw = Get-Content -Path VMTemplates.txt -Raw
$VMTemplates = $JsonSerial.DeserializeObject($VMTemplatesRaw)
 
# Restore Host Network Adapters
$HostNetworkAdaptersRaw = Get-Content -Path HostNetworkAdapters.txt -Raw
$HostNetworkAdapters = $JsonSerial.DeserializeObject($HostNetworkAdaptersRaw)
 
# Restore Virtual Machines
$VirtualMachines = Get-Content -Path VirtualMachines.txt -Raw
$VirtualMachines = $JsonSerial.DeserializeObject($VirtualMachines)
 
Write-Host "Working on Host Groups.."
Write-Host " "
 
# Set Host Groups
foreach ($HostGroup in $HostGroups)
{
	$CheckHostGroup = Get-SCVMHostGroup | Where Path -eq $HostGroup.Path
	if (!$CheckHostGroup)
	{
		Write-Host $HostGroup.Name is not exist. Creating..
		$ParentHostGroup = @(Get-SCVMHostGroup | Where {$_.Path -eq $HostGroup.ParentHostGroup.Path})[0]
		$NewHostGroup = New-SCVMHostGroup -Name $HostGroup.Name -Description $HostGroup.Description -ParentHostGroup $ParentHostGroup -EnableUnencryptedFileTransfer $HostGroup.AllowUnencryptedTransfers -InheritNetworkSettings $HostGroup.InheritNetworkSettings
	}
	else
	{
		Write-Host $HostGroup.Name is already available.
	}
}
 
Write-Host " "
Write-Host " "
Write-Host "Working on Logical Networks.."
Write-Host " "
 
# Set Logical Networks
foreach ($LogicalNetwork in $LogicalNetworks)
{
	$CheckLogicalNetwork = Get-SCLogicalNetwork -Name $LogicalNetwork.Name
	if (!$CheckLogicalNetwork)
	{
		Write-Host $LogicalNetwork.Name is not exist. Creating..
		$NewLogicalNetwork = New-SCLogicalNetwork -Name $LogicalNetwork.Name -Description $LogicalNetwork.Description -EnableNetworkVirtualization $LogicalNetwork.NetworkVirtualizationEnabled -UseGRE $LogicalNetwork.UseGRE -IsPVLAN $LogicalNetwork.IsPVLAN -LogicalNetworkDefinitionIsolation $LogicalNetwork.IsLogicalNetworkDefinitionIsolated
	}
	else
	{
		Write-Host $LogicalNetwork.Name is already available.
	}
}
 
Write-Host " "
Write-Host " "
Write-Host "Working on Logical Network Definitions.."
Write-Host " "
 
# Set Logical Network Definition
foreach ($LogicalNetworkDefinition in $LogicalNetworkDefinitions)
{
	$CheckLogicalNetworkDefinition = Get-SCLogicalNetworkDefinition -Name $LogicalNetworkDefinition.Name
	if (!$CheckLogicalNetworkDefinition)
	{
		Write-Host $LogicalNetworkDefinition.Name is not exist. Creating..
 
		# Get Logical Network
		$LogicalNetwork = Get-SCLogicalNetwork -Name $LogicalNetworkDefinition.LogicalNetwork.Name
 
		# Get Subnet VLANS
		$SubnetVLANPool = @()
		foreach ($SubnetVLAN in $LogicalNetworkDefinition.SubnetVLans)
		{
			$SubnetInfo = $SubnetVLAN.Split("-")
			$SubnetVLANPool += New-SCSubnetVLan -Subnet $SubnetInfo[0] -VLanID $SubnetInfo[1]
		}
 
		# Get VMHost Groups
		$HostGroupPool = @()
		foreach ($HostGroup in $LogicalNetworkDefinition.HostGroups)
		{
			$HostGroupPool += Get-SCVMHostGroup | Where Path -eq $HostGroup
 
		}
 
		# Create Logical Network Definition
		$NewLogicalNetworkDefinition = New-SCLogicalNetworkDefinition -Name $LogicalNetworkDefinition.Name -LogicalNetwork $LogicalNetwork -SubnetVLan $SubnetVLANPool -VMHostGroup $HostGroupPool
	}
	else
	{
		Write-Host $LogicalNetworkDefinition.Name is already available.
	}
}
 
Write-Host " "
Write-Host " "
Write-Host "Working on Static IP Address Pools.."
Write-Host " "
 
# Set Static IP Address Pool
foreach ($StaticIPAddressPool in $StaticIPAddressPools)
{
	$CheckStaticIPAddressPool = Get-SCStaticIPAddressPool -Name $StaticIPAddressPool.Name
	if (!$CheckStaticIPAddressPool)
	{
		Write-Host $StaticIPAddressPool.Name is not exist. Creating..
 
		# Create Gateway
		$Gateways = @()
		foreach ($DefaultGateway in $StaticIPAddressPool.DefaultGateways)
		{
			$Gateways += New-SCDefaultGateway -IPAddress $DefaultGateway
		}
 
		# Get Logical Network Definition
		$LogicalNetworkDefinition = Get-SCLogicalNetworkDefinition -Name $StaticIPAddressPool.LogicalNetworkDefinition.Name
 
		# Create Static IP Address Pool
		$NewStaticIPAddressPool = New-SCStaticIPAddressPool -Name $StaticIPAddressPool.Name -Description $StaticIPAddressPool.Description -Subnet $StaticIPAddressPool.Subnet -Vlan $StaticIPAddressPool.VLanID -IPAddressRangeStart $StaticIPAddressPool.IPAddressRangeStart -IPAddressRangeEnd $StaticIPAddressPool.IPAddressRangeEnd -IPAddressReservedSet $StaticIPAddressPool.IPAddressReservedSet -DNSSuffix $StaticIPAddressPool.DNSSuffix -EnableNetBIOS $StaticIPAddressPool.EnableNetBIOS -LogicalNetworkDefinition $LogicalNetworkDefinition -DNSServer $StaticIPAddressPool.DNSServers -WINSServer $StaticIPAddressPool.WINSServers -DNSSearchSuffix $StaticIPAddressPool.DNSSearchSuffixes -DefaultGateway $Gateways
	}
	else
	{
		Write-Host $StaticIPAddressPool.Name is already available.
	}
}
 
Write-Host " "
Write-Host " "
Write-Host "Working on VM Networks.."
Write-Host " "
 
# Set VM Networks
foreach ($VMNetwork in $VMNetworks)
{
	# Get User Role
	$UserRole = Get-SCUserRole -Name $VMNetwork.UserRole.Name
 
	# Get Logical Network
	$LogicalNetwork = Get-SCLogicalNetwork -Name $VMNetwork.LogicalNetwork.Name
 
	$CheckVMNetwork = Get-SCVMNetwork -Name $VMNetwork.Name
	if (!$CheckVMNetwork)
	{
		Write-Host $VMNetwork.Name is not exist. Creating..
 
		$UserRole = Get-SCUserRole -Name $VMNetwork.UserRole.Name
		$LogicalNetwork = Get-SCLogicalNetwork -Name $VMNetwork.LogicalNetwork.Name
		$NewSCVMNetwork = New-SCVMNetwork -Name $VMNetwork.Name -Description $VMNetwork.Description -UserRole $UserRole -LogicalNetwork $LogicalNetwork -RoutingDomainId $VMNetwork.RoutingDomainId -IsolationType $VMNetwork.IsolationType -PAIPAddressPoolType $VMNetwork.PAIPAddressPoolType -CAIPAddressPoolType $VMNetwork.CAIPAddressPoolType -Owner $VMNetwork.Owner
	}
	else
	{
		Write-Host $VMNetwork.Name is already available.
	}	
}
 
Write-Host " "
Write-Host " "
Write-Host "Working on VM Subnets.."
Write-Host " "
 
# Set VM Subnets
foreach ($VMSubnet in $VMSubnets)
{
	# Get Subnet VLAN Information
	$SubnetInfo = $VMSubnet.SubnetVLans.Split("-")
	$SubnetName = $SubnetInfo[0]
	$SubnetVLanID = $SubnetInfo[1]
 
	# Create Subnet VLAN
	$SubnetVLAN = New-SCSubnetVLan -Subnet $SubnetName -VLanID $SubnetVLanID
 
	# Get Logical Network Definition
	$LogicalNetworkDefinition = Get-SCLogicalNetworkDefinition -VLanID $SubnetVLanID
 
	# Get VM Network
	$VMNetwork = Get-SCVMnetwork -Name $VMSubnet.VMNetwork.Name
 
	$CheckVMSubnet = Get-SCVMSubnet -Name $VMSubnet.Name
	if (!$CheckVMSubnet)
	{
		Write-Host $VMSubnet.Name is not exist. Creating..
 
		$NewVMSubnet = New-SCVMSubnet -Name $VMSubnet.Name -Description $VMSubnet.Description -LogicalNetworkDefinition $LogicalNetworkDefinition -SubnetVLan $SubnetVLAN -VMNetwork $VMNetwork -MaxNumberOfPorts $VMSubnet.MaxNumberOfPorts
	}
	else
	{
		Write-Host $VMSubnet.Name is already available.
	}	
}
 
Write-Host " "
Write-Host " "
Write-Host "Working on Clouds.."
Write-Host " "
 
# Set Clouds
foreach ($Cloud in $Clouds)
{
	$CheckCloud = Get-SCCloud -Name $Cloud.Name
	if (!$CheckCloud)
	{
		Write-Host $Cloud.Name is not exist. Creating..
 
		# Get VMHost Groups
		$HostGroupPool = @()
		foreach ($HostGroup in $Cloud.HostGroup)
		{
			$HostGroupPool += Get-SCVMHostGroup | Where Path -eq $HostGroup
		}
 
		# Create Cloud
		$NewCloud = New-SCCloud -Name $Cloud.Name -VMHostGroup $HostGroupPool -DisasterRecoverySupported $Cloud.IsDRProtected
	}
	else
	{
		Write-Host $Cloud.Name is already available.
	}
}
 
Write-Host " "
Write-Host " "
Write-Host "Working on Capability Profiles.."
Write-Host " "
 
# Set Capability Profiles
foreach ($Cloud in $Clouds)
{
	$CheckCloud = Get-SCCloud -Name $Cloud.Name
	if ($CheckCloud)
	{		
		# Get Capability Profiles
		$CapabilityProfilePool = @()
 
		foreach ($CapabilityProfileItem in $Cloud.CapabilityProfiles)
		{
			$CapabilityProfile = Get-SCCapabilityProfile -Name $CapabilityProfileItem
 
			if ($CapabilityProfile)
			{
				if ($CheckCloud.CapabilityProfiles.Name -notcontains $CapabilityProfile.Name)
				{
					Write-Host $CapabilityProfile.Name is added to capability profile pool.
 
					$CapabilityProfilePool += $CapabilityProfile
				}
				else
				{
					Write-Host $CapabilityProfile.Name is already exist on cloud capability profile.
				}
			}
			else
			{
				Write-Host $CapabilityProfileItem is not exist. Please check your capability profile config.
			}
		}
 
		# Set Capability Profile
		if ($CapabilityProfilePool)
		{
			Write-Host Setting Capability Profiles on $Cloud.Name ..
 
			$SetCloud = $CheckCloud | Set-SCCloud -AddCapabilityProfile $CapabilityProfilePool
		}
		else
		{
			Write-Host No additional capability profiles are exist for $Cloud.Name ..
		}
	}
	else
	{
		Write-Host $Cloud.Name is not exist. Please check your cloud configuration.
	}
}
 
Write-Host " "
Write-Host " "
Write-Host "Working on Library Shares.."
Write-Host " "
 
$LibraryShares = Get-SCLibraryShare
 
# Set Library Shares
foreach ($Cloud in $Clouds)
{
	$CheckCloud = Get-SCCloud -Name $Cloud.Name
	if ($CheckCloud)
	{		
		# Get Library Shares
		$LibrarySharePool = @()
 
		foreach ($LibrarySharePath in $Cloud.ReadableLibraryPaths)
		{
			$LibraryShareName = ($LibraryShares | Where Path -eq $LibrarySharePath).Name
			$LibraryShare = Get-SCLibraryShare | Where Name -eq $LibraryShareName
 
			if ($LibraryShare)
			{
				if ($LibrarySharePool -notcontains $LibraryShare.Path)
				{
					Write-Host $LibraryShareName is added to library share pool.
 
					$LibrarySharePool += $LibraryShare
				}
				else
				{
					Write-Host $LibraryShareName is already exist on cloud.
				}
			}
			else
			{
				Write-Host $LibraryShareName is not exist. Please update your library shares manually.
			}
		}
 
		# Set Library Shares
		if ($LibrarySharePool)
		{
			Write-Host Setting Library Shares on $Cloud.Name ..
 
			$SetCloud = $CheckCloud | Set-SCCloud -AddReadOnlyLibraryShare $LibrarySharePool
		}
		else
		{
			Write-Host No additional library shares are exist for $Cloud.Name ..
		}
	}
	else
	{
		Write-Host $Cloud.Name is not exist. Please check your cloud configuration.
	}
}
 
Write-Host " "
Write-Host " "
Write-Host "Working on User Roles.."
Write-Host " "
 
# Set User Roles
foreach ($UserRole in $UserRoles)
{
	$CheckUserRole = Get-SCUserRole -Name $UserRole.Name
	if (!$CheckUserRole)
	{
		Write-Host $UserRole.Name is not exist. Creating..
 
		# Create User Role
		$NewUserRole = New-SCUserRole -Name $UserRole.Name -UserRoleProfile $UserRole.UserRoleProfile -Description $UserRole.Description -ParentUserRole $UserRole.ParentUserRole.ParentUserRole
 
		# Get Scopes
		$CloudScope = @()
		foreach ($Cloud in $UserRole.Cloud.Name)
		{
			$CloudScope += Get-SCCloud -Name $Cloud
		}
 
		# Set User Role
		$GetUserRole = Get-SCUserRole -Name $UserRole.Name
		$SetUserRole = Set-SCUserRole -UserRole $GetUserRole -AddScope $CloudScope
 
		# Get User Role Members
		$UserRoleMembers = $UserRole.Members
 
		# Set User Role Members
		foreach ($UserRoleMember in $UserRoleMembers)
		{
			$UserRoleMemberName = $UserRoleMember.Name
 
			Write-Host $UserRoleMemberName is being applied on $UserRoleName user role..
 
			$SetUserRole = Set-SCUserRole -UserRole $GetUserRole -AddMember @("$UserRoleMemberName")
		}
	}
	else
	{
		Write-Host $UserRole.Name is already available.
	}
}
 
Write-Host " "
Write-Host " "
Write-Host "Working on User Role Quotas.."
Write-Host " "
 
# Set User Role Quotas
foreach ($UserRoleQuota in $UserRoleQuotas)
{
	# Get User Role
	$UserRoleName = $Null;
	$UserRoleName = ($UserRoles | Where ID -eq $UserRoleQuota.RoleID).Name
	$UserRole = Get-SCUserRole -Name $UserRoleName
 
	# Get Cloud
	$CloudName = $Null;
	$CloudName = ($Clouds | Where ID -eq $UserRoleQuota.CloudID).Name
	$Cloud = Get-SCCloud -Name $CloudName
	$GetUserRoleQuota = Get-SCUserRoleQuota -UserRole $UserRole -Cloud $Cloud
 
	Write-Host $UserRole.Name role quota is being applied on $Cloud.Name cloud..
 
	# Set User Role Quota
	if ($UserRoleQuota.CPUCount)
	{
		$SetUserRoleQuota = $GetUserRoleQuota | Set-SCUserRoleQuota -CPUCount $UserRoleQuota.CPUCount
	}
	else
	{
		$SetUserRoleQuota = $GetUserRoleQuota | Set-SCUserRoleQuota -UseCPUCountMaximum
	}
 
	# Set User Role Quota
	if ($UserRoleQuota.MemoryMB)
	{
		$SetUserRoleQuota = $GetUserRoleQuota | Set-SCUserRoleQuota -MemoryMB $UserRoleQuota.MemoryMB
	}
	else
	{
		$SetUserRoleQuota = $GetUserRoleQuota | Set-SCUserRoleQuota -UseMemoryMBMaximum
	}
 
	# Set User Role Quota
	if ($UserRoleQuota.StorageGB)
	{
		$SetUserRoleQuota = $GetUserRoleQuota | Set-SCUserRoleQuota -StorageGB $UserRoleQuota.StorageGB
	}
	else
	{
		$SetUserRoleQuota = $GetUserRoleQuota | Set-SCUserRoleQuota -UseStorageGBMaximum
	}
 
	# Set User Role Quota
	if ($UserRoleQuota.VMCount)
	{
		$SetUserRoleQuota = $GetUserRoleQuota |Set-SCUserRoleQuota -VMCount $UserRoleQuota.VMCount
	}
	else
	{
		$SetUserRoleQuota = $GetUserRoleQuota |Set-SCUserRoleQuota -UseVMCountMaximum
	}
 
	# Set User Role Quota
	if ($UserRoleQuota.CustomQuotaCount)
	{
		$SetUserRoleQuota = $GetUserRoleQuota | Set-SCUserRoleQuota -CustomQuotaCount $UserRoleQuota.CustomQuotaCount
	}
	else
	{
		$SetUserRoleQuota = $GetUserRoleQuota | Set-SCUserRoleQuota -UseCustomQuotaCountMaximum
	}
}
 
Write-Host " "
Write-Host " "
Write-Host "Working on VM Templates.."
Write-Host " "
 
# Set VM Templates
foreach ($VMTemplate in $VMTemplates)
{
	$CheckVMTemplate = Get-SCVMTemplate -Name $VMTemplate.Name
	if (!$CheckVMTemplate)
	{
		Write-Host $VMTemplate.Name is not exist. Creating..
 
		# Set Variables
		$OperatingSystem = $Null;
		$VirtualHardDisk = $Null;
 
		# Clear Result Code
		$ResultCode = "1"
 
		# Get Operating System
		$OperatingSystem = Get-SCOperatingSystem | Where Name -eq $VMTemplate.OperatingSystem.Name
 
		if (!$OperatingSystem)
		{
			$ResultCode = "-1"
 
			Write-Host Operating System for $VMTemplate.Name is not exist. Please check your library config.
		}
 
		# Get Virtual Hard Disk
		$VirtualHardDisk = Get-SCVirtualHardDisk | Where Location -eq $VMTemplate.VirtualHardDisks.Location
 
		if (!$VirtualHardDisk)
		{
			$ResultCode = "-1"
 
			Write-Host Virtual Hard Disk for $VMTemplate.Name is not exist. Please check your library config.
		}	
 
		# Create Job Group
		$JobGroupGuid = [System.Guid]::NewGuid().toString()
 
		# Get Virtual Network Adapter
		foreach ($VirtualNetworkAdapter in $VMTemplate.VirtualNetworkAdapters)
		{
			# Get IPv4 Address Type
			if ($VirtualNetworkAdapter.IPv4AddressType -eq "1")
			{
				$IPv4AddressType = "Static"
			}
			else
			{
				$IPv4AddressType = "Dynamic"
			}
 
			# Get IPv6 Address Type
			if ($VirtualNetworkAdapter.IPv6AddressType -eq "1")
			{
				$IPv6AddressType = "Static"
			}
			else
			{
				$IPv6AddressType = "Dynamic"
			}
 
			# Get VM Network
			$VMNetwork = Get-SCVMNetwork -Name $VirtualNetworkAdapter.VMNetwork
 
			# Get VM Subnet
			$VMSubnet = Get-SCVMSubnet -Name $VMNetwork.VMSubnet.Name
 
			if ($VirtualNetworkAdapter.VirtualNetworkAdapterType -eq "2")
			{
				# Synthetic
				New-SCVirtualNetworkAdapter -JobGroup $JobGroupGuid -MACAddress $VirtualNetworkAdapter.MACAddress -MACAddressType $VirtualNetworkAdapter.MACAddressType -Synthetic -EnableVMNetworkOptimization $VirtualNetworkAdapter.VMNetworkOptimizationEnabled -EnableMACAddressSpoofing $VirtualNetworkAdapter.MACAddressSpoofingEnabled -IPv4AddressType $IPv4AddressType -IPv6AddressType $IPv6AddressType -VMSubnet $VMSubnet -VMNetwork $VMNetwork 
			}
			else
			{
				# Emulated
				New-SCVirtualNetworkAdapter -JobGroup $JobGroupGuid -MACAddress $VirtualNetworkAdapter.MACAddress -MACAddressType $VirtualNetworkAdapter.MACAddressType -EnableVMNetworkOptimization $VirtualNetworkAdapter.VMNetworkOptimizationEnabled -EnableMACAddressSpoofing $VirtualNetworkAdapter.MACAddressSpoofingEnabled -IPv4AddressType $IPv4AddressType -IPv6AddressType $IPv6AddressType -VMSubnet $VMSubnet -VMNetwork $VMNetwork 
			}
		}
 
		if ($ResultCode -ne "-1")
		{		
			# Set VM Template
			$NewVMTemplate = New-SCVMTemplate -JobGroup $JobGroupGuid -Name $VMTemplate.Name -Description $VMTemplate.Description -OperatingSystem $OperatingSystem -VirtualHardDisk $VirtualHardDisk
 
			if ($NewVMTemplate)
			{
				Write-Host $VMTemplate.Name is successfully created.
			}
			else
			{
				Write-Host $VMTemplate.Name is failed to create. Please check your library configuration.
			}
		}
	}
	else
	{
		Write-Host $VMTemplate.Name is already available.
	}
}
 
Write-Host " "
Write-Host " "
Write-Host "Working on VM Template Properties.."
Write-Host " "
 
# Set VM Templates
foreach ($VMTemplate in $VMTemplates)
{
	$CheckVMTemplate = Get-SCVMTemplate -Name $VMTemplate.Name
	if (!$CheckVMTemplate)
	{
		Write-Host $VMTemplate.Name is not exist. Please check your library configuration..
	}
	else
	{
		Write-Host Working on $VMTemplate.Name properties..
 
		# Clear Variables	
		$UserRole = $Null;
		$Owner = $Null;
		$CapabilityProfile = $Null;
		$IsHighlyAvailable = $Null;
		$IsDRProtectionRequired = $Null;
		$ApplicationProfile = $Null;
		$GetApplicationProfile = $Null;
		$SQLProfile = $Null;
		$GetSQLProfile = $Null;
		$AnswerFile = $Null;
		$CPUType = $Null;
		$CPUCount = $Null;
		$CPURelativeWeight = $Null;
		$CPUReserve = $Null;
		$CPUMaximumPercent = $Null;
		$CPUPerVirtualNumaNodeMaximum = $Null;
		$VirtualNumaNodesPerSocketMaximum = $Null;
		$NumaIsolationRequired = $Null;
		$MemoryMB = $Null;
		$DynamicMemoryEnabled = $Null;
		$MemoryWeight = $Null;
		$MemoryPerVirtualNumaNodeMaximumMB = $Null;
		$VirtualVideoAdapterEnabled = $Null;
		$MonitorMaximumCount = $Null;
		$MonitorMaximumResolution = $Null;
		$HAVMPriority = $Null;
		$SysprepScript = $Null;
		$SysprepScriptName = $Null;
		$SysprepScriptFile = $Null;
		$SysprepFilePathName = $Null;
		$ComputerName = $Null;
		$FullName = $Null;
		$OrganizationName = $Null;
		$TimeZone = $Null;
		$AutoLogonCount = $Null;
		$GuiRunOnceCommands = $Null;
		$GuiRunOnceCommandsArray = $Null;
		$LinuxAdministratorSSHKey = $Null;
		$LinuxDomainName = $Null;
		$QuotaPoint = $Null;
		$Tag = $Null;
		$CostCenter = $Null;
 
		# Get User Role
		$UserRole = Get-SCUserRole -Name $VMTemplate.UserRole.Name
 
		if ($UserRole)
		{
			# Set User Role
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -UserRole $UserRole
		}
 
		# Get Template Owner
		$Owner = $VMTemplate.Owner
 
		if ($Owner)
		{
			# Set Template Owner
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -Owner $Owner
		}
 
		# Get Capability Profile
		$CapabilityProfile = Get-SCCapabilityProfile -Name $VMTemplate.CapabilityProfile.Name
 
		if ($CapabilityProfile)
		{
			# Set Capability Profile
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -CapabilityProfile $CapabilityProfile
		}
 
		# Get Availability Status
		$IsHighlyAvailable = $VMTemplate.IsHighlyAvailable
 
		if ($IsHighlyAvailable)
		{
			# Set Availability Status
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -HighlyAvailable $IsHighlyAvailable
		}
 
		# Get DR Protection
		$IsDRProtectionRequired = $VMTemplate.IsDRProtectionRequired
 
		if ($IsDRProtectionRequired)
		{
			# Set DR Protection Status
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -DRProtectionRequired $IsDRProtectionRequired
		}
 
		# Get Application Profile
		 $ApplicationProfile = $VMTemplate.ApplicationProfile
 
		if ($ApplicationProfile)
		{
			# Get Application Profile
			$GetApplicationProfile = Get-SCApplicationProfile -Name $ApplicationProfile.Name
 
			if ($GetApplicationProfile)
			{
				# Set Application Profile
				$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -ApplicationProfile $GetApplicationProfile
			}
		}
 
		# Get SQL Profile
		 $SQLProfile = $VMTemplate.SQLProfile
 
		if ($SQLProfile)
		{
			# Get SQL Profile
			$GetSQLProfile = Get-SCSQLProfile -Name $SQLProfile.Name
 
			if ($GetSQLProfile)
			{
				# Set SQL Profile
				$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -SQLProfile $GetSQLProfile
			}
		}
 
		# Get AnswerFile
		$AnswerFile = $VMTemplate.AnswerFile
 
		if ($AnswerFile)
		{
			# Set Answer File
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -AnswerFile $AnswerFile
		}
 
		# Get CPU Type
		$CPUType = Get-SCCPUType | Where Name -eq $VMTemplate.CPUType.Name
 
		if ($CPUType)
		{
			# Set CPU Type
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -CPUType $CPUType
		}
 
		# Get CPU Count
		$CPUCount = $VMTemplate.CPUCount
 
		if ($CPUCount)
		{
			# Set CPU Count
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -CPUCount $CPUCount
		}
 
		# Get CPU Relative Weight
		$CPURelativeWeight = $VMTemplate.CPURelativeWeight
 
		if ($CPURelativeWeight)
		{
			# Set CPU Relative Weight
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -CPURelativeWeight $CPURelativeWeight
		}
 
		# Get CPU Reserve
		$CPUReserve = $VMTemplate.CPUReserve
 
		if ($CPUReserve)
		{
			# Set CPU Reserve
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -CPUReserve $CPUReserve
		}
 
		# Get CPU Maximum Percent
		$CPUMaximumPercent = $VMTemplate.CPUMaximumPercent
 
		if ($CPUMaximumPercent)
		{
			# Set CPU Maximum Percent
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -CPUMaximumPercent $CPUMaximumPercent
		}
 
		# Get CPU Virtualization Numa Node Maximum
		$CPUPerVirtualNumaNodeMaximum = $VMTemplate.CPUPerVirtualNumaNodeMaximum
 
		if ($CPUMaximumPercent)
		{
			# Set CPU Virtualization Numa Node Maximum
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -CPUMaximumPercent $CPUMaximumPercent
		}
 
		# Get Virtual Numa Nodes Per Socket Maximum
		$VirtualNumaNodesPerSocketMaximum = $VMTemplate.VirtualNumaNodesPerSocketMaximum
 
		if ($VirtualNumaNodesPerSocketMaximum)
		{
			# Set Virtual Numa Nodes Per Socket Maximum
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -VirtualNumaNodesPerSocketMaximum $VirtualNumaNodesPerSocketMaximum
		}
 
		# Get Numa Isolation Required
		$NumaIsolationRequired = $VMTemplate.NumaIsolationRequired 
 
		if ($NumaIsolationRequired)
		{
			# Set Numa Isolation Required
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -NumaIsolationRequired $NumaIsolationRequired
		}
 
		# Get Memory MB
		$MemoryMB = $VMTemplate.Memory
 
		if ($MemoryMB)
		{
			# Set Memory MB
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -MemoryMB $MemoryMB
		}
 
		# Get Dynamic Memory
		$DynamicMemoryEnabled = $VMTemplate.DynamicMemoryEnabled
 
		if ($DynamicMemoryEnabled -eq $True)
		{
			# Set Dynamic Memory
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -DynamicMemoryEnabled $DynamicMemoryEnabled -DynamicMemoryMinimumMB $VMTemplate.DynamicMemoryMinimumMB -DynamicMemoryMaximumMB $VMTemplate.DynamicMemoryMaximumMB -DynamicMemoryBufferPercentage $VMTemplate.DynamicMemoryBufferPercentage
		}
 
		# Get Memory Weight
		$MemoryWeight = $VMTemplate.MemoryWeight
 
		if ($MemoryWeight)
		{
			# Set Memory Weight
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -MemoryWeight $MemoryWeight
		}
 
		# Get Memory Per Virtual Numa Node Maximum MB
		$MemoryPerVirtualNumaNodeMaximumMB = $VMTemplate.MemoryPerVirtualNumaNodeMaximumMB
 
		if ($MemoryPerVirtualNumaNodeMaximumMB)
		{
			# Set Memory Per Virtual Numa Node Maximum MB
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -MemoryPerVirtualNumaNodeMaximumMB $MemoryPerVirtualNumaNodeMaximumMB
		}
 
		# Get Virtual Video Adapter Status
		$VirtualVideoAdapterEnabled = $VMTemplate.VirtualVideoAdapterEnabled
 
		if ($VirtualVideoAdapterEnabled)
		{
			# Set Virtual Video Adapter Status
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -VirtualVideoAdapterEnabled $VirtualVideoAdapterEnabled
		}
 
		# Get Monitor Maximum Count
		$MonitorMaximumCount = $VMTemplate.MonitorMaximumCount
 
		if ($MonitorMaximumCount)
		{
			# Set Monitor Maximum Count
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -MonitorMaximumCount $MonitorMaximumCount
		}
 
		# Get Monitor Maximum Resolution
		$MonitorMaximumResolution = $VMTemplate.MonitorMaximumResolution 
 
		if ($MonitorMaximumResolution)
		{
			# Set Monitor Maximum Resolution
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -MonitorMaximumResolution $MonitorMaximumResolution
		}
 
		# Get HAVM Priority
		$HAVMPriority = $VMTemplate.HAVMPriority 
 
		if ($HAVMPriority)
		{
			# Set Monitor Maximum Resolution
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -HAVMPriority $HAVMPriority
		}
 
		# Get Sysprep Script
		$SysprepScript = $VMTemplate.SysprepScript
 
		if ($SysprepScript)
		{
			$SysprepScriptName = $SysprepScript.Name
			$SysprepScriptFile = Get-Script | where {$_.Name -eq $SysprepScriptName}
 
			if (!$SysprepScriptFile)
			{
				$SysprepFilePathName = ($VMTemplate.SysprepScript.SharePath).Split("\")[-1]
				$SysprepScriptFile = Get-Script | where {$_.SharePath -like "*$SysprepFilePathName"}
			}
 
			# Set Sysprep Script
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -SysPrepFile $SysprepScriptFile -MergeAnswerFile $True
		}
 
		# Get Computer Name
		$ComputerName = $VMTemplate.ComputerName
 
		if ($ComputerName)
		{
			# Set Monitor Maximum Resolution
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -ComputerName $ComputerName
		}
 
		# Get Full Name
		$FullName = $VMTemplate.FullName
 
		if ($FullName)
		{
			# Set Monitor Maximum Resolution
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -FullName $FullName
		}
 
		# Get Organization Name
		$OrganizationName = $VMTemplate.OrgName
 
		if ($OrganizationName)
		{
			# Set Organization Name
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -OrganizationName $OrganizationName
		}
 
		# Get Time Zone
		$TimeZone = $VMTemplate.TimeZone
 
		if ($TimeZone)
		{
			# Set Time Zone
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -TimeZone $TimeZone
		}
 
		# Get Auto Logon Count
		$AutoLogonCount = $VMTemplate.AutoLogonCount
 
		if ($AutoLogonCount)
		{
			# Set Auto Logon Count
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -AutoLogonCount $AutoLogonCount
		}
 
		# Get Gui Run Once Commands
		$GuiRunOnceCommands = $VMTemplate.GuiRunOnceCommands
 
		if ($GuiRunOnceCommands)
		{
			# Create Array
			$GuiRunOnceCommandsArray = @()
 
			foreach ($GuiRunOnceCommand in $GuiRunOnceCommands)
			{
				$GuiRunOnceCommandsArray += $GuiRunOnceCommand
			}
 
			# Set Gui Run Once Commands
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -GuiRunOnceCommands $GuiRunOnceCommandsArray
		}
 
		# Get Linux Administrator SSH Key
		$LinuxAdministratorSSHKey = $VMTemplate.LinuxAdministratorSSHKey
 
		if ($LinuxAdministratorSSHKey)
		{
			# Set Linux Administrator SSH Key
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -LinuxAdministratorSSHKey $LinuxAdministratorSSHKey
		}		
 
		# Get Linux Domain Name
		$LinuxDomainName = $VMTemplate.LinuxDomainName
 
		if ($LinuxDomainName)
		{
			# Set Linux Domain Name
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -LinuxDomainName $LinuxDomainName
		}
 
		# Get Quota Point
		$QuotaPoint = $VMTemplate.QuotaPoint
 
		if ($QuotaPoint)
		{
			# Set Quota Point
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -QuotaPoint $QuotaPoint
		}
 
		# Get Tag
		$Tag = $VMTemplate.Tag
 
		if ($Tag)
		{
			# Set Tag
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -Tag $Tag
		}
 
		# Get Cost Center
		$CostCenter = $VMTemplate.CostCenter
 
		if ($CostCenter)
		{
			# Set Cost Center
			$SetVMTemplate = $CheckVMTemplate | Set-SCVMTemplate -CostCenter $CostCenter
		}
	}
}

After you reassociate all Hyper-V hosts in new SCVMM 2012 R2 server, you can execute this script to restore hardware properties:

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
Write-Host " "
Write-Host " "
Write-Host "Working on Host Network Adapters.."
Write-Host " "
 
# Set Host Network Adapters
foreach ($HostNetworkAdapter in $HostNetworkAdapters)
{
	Write-Host Working on $HostNetworkAdapter.Name of $HostNetworkAdapter.VMHost ..
 
	# Clear Variables
	$VMHostNetworkAdapter = $Null;
 
	# Create Job Group
	$JobGroupGuid = [System.Guid]::NewGuid().toString()
 
	# Get Host Network Adapter
	$VMHost = Get-SCVMHost -ComputerName $HostNetworkAdapter.VMHost
	$VMHostNetworkAdapter =  Get-SCVMHostNetworkAdapter -Name $HostNetworkAdapter.Name -VMHost $VMHost
 
	if ($VMHostNetworkAdapter)
	{	
		# Set Changes
		$SetVMHostNetworkAdapter = Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $VMHostNetworkAdapter -Description $HostNetworkAdapter.Description -AvailableForPlacement $HostNetworkAdapter.AvailableForPlacement -UsedForManagement $HostNetworkAdapter.UsedForManagement -JobGroup $JobGroupGuid
 
		if ($HostNetworkAdapter.NetworkLocation)
		{
			# Get Logical Network
			$LogicalNetwork = Get-SCLogicalNetwork -Name $HostNetworkAdapter.NetworkLocation
 
			if ($HostNetworkAdapter.SubnetVLans)
			{	
				# Get Subnet VLANS
				$SubnetVLANs = ($HostNetworkAdapter.SubnetVLans).Split(" ")
 
				# Create Subnet VLAN Pool
				$SubnetVLANPool = @()
 
				foreach ($SubnetVLAN in $SubnetVLANs)
				{
					$SubnetInfo = $SubnetVLAN.Split("-")
					$SubnetAddr = $SubnetInfo[0]
					$SubnetVLANID = $SubnetInfo[1]
					$SubnetVLANPool += New-SCSubnetVLan -Subnet $SubnetAddr -VLanID $SubnetVLANID
				}
 
				# Set Changes
				$SetVMHostNetworkAdapter = Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $VMHostNetworkAdapter -AddOrSetLogicalNetwork $logicalNetwork -SubnetVLan $SubnetVLANPool -JobGroup $JobGroupGuid
 
				# Set VM Host
				$SetVMHost = Set-SCVMHost -VMHost $VMHost -JobGroup $JobGroupGuid
			}
			else
			{
				# Set Changes
				$SetVMHostNetworkAdapter = Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $VMHostNetworkAdapter -AddOrSetLogicalNetwork $logicalNetwork -JobGroup $JobGroupGuid
 
				# Set VM Host
				$SetVMHost = Set-SCVMHost -VMHost $VMHost -JobGroup $JobGroupGuid
			}
		}
	}
	else
	{
		Write-Host $HostNetworkAdapter.Name is not exist on host. Please refresh your SCVMM environment.
	}
}

After hardware updates, you can execute this script to restore virtual machine properties:

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
Write-Host " "
Write-Host " "
Write-Host "Working on Virtual Machines.."
Write-Host " "
 
# Set Virtual Machines
foreach ($VirtualMachine in $VirtualMachines)
{
	Write-Host Working on $VirtualMachine.Name ..
 
	# Clear Variables
	$VM = $Null;
 
	# Get Virtual Machine
	$VM = Get-SCVirtualMachine | Where VMId -eq $VirtualMachine.VMId
 
	if ($VM)
	{
		if ($VirtualMachine.Cloud.Name)
		{
			# Get Cloud Info
			$CloudName = $VirtualMachine.Cloud.Name
 
			# Get Cloud
			$Cloud = Get-SCCloud -Name $CloudName
 
			# Set Virtual Machine Properties
			$SetVM = $VM | Set-SCVirtualMachine -Cloud $Cloud
		}			
 
		if ($VirtualMachine.UserRole.Name)
		{
			# Get User Role Info
			$UserRoleName = $VirtualMachine.UserRole.Name
 
			# Get User Role
			$UserRole = Get-SCUserRole -Name $UserRoleName
 
			# Set Virtual Machine Properties
			$SetVM = $VM | Set-SCVirtualMachine -UserRole $UserRole
		}
 
		if ($VirtualMachine.Owner)
		{
			# Get Virtual Machine Owner Info
			$Owner = $VirtualMachine.Owner
 
			# Set Virtual Machine Properties
			$SetVM = $VM | Set-SCVirtualMachine -Owner $Owner 
		}
 
		if ($VirtualMachine.CostCenter)
		{
			# Set Virtual Machine Properties
			$SetVM = $VM | Set-SCVirtualMachine -CostCenter $VirtualMachine.CostCenter
		}
 
		if ($VirtualMachine.Description)
		{
			# Set Virtual Machine Properties
			$SetVM = $VM | Set-SCVirtualMachine -Description $VirtualMachine.Description
		}
 
		if ($VirtualMachine.Tag)
		{
			# Set Virtual Machine Properties
			$SetVM = $VM | Set-SCVirtualMachine -Tag $VirtualMachine.Tag
		}
 
		if ($VirtualMachine.QuotaPoint)
		{
			# Set Virtual Machine Properties
			$SetVM = $VM | Set-SCVirtualMachine -QuotaPoint $VirtualMachine.QuotaPoint
		}
	}
	else
	{
		Write-Host $VirtualMachine.Name is not exist on SCVMM. Please refresh your SCVMM environment.
	}
}

If you need to update Domain Join Credentials of VM templates, use following script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Write-Host " "
Write-Host " "
Write-Host "Working on Domain Join Credentials"
Write-Host " "
 
# Get Templates
$VMTemplates = Get-SCVMTemplate
 
# Set Domain
$Domain = "domain.com"
 
# Get Credentials
$DomainJoinCredential = Get-Credential
 
# Set Templates
foreach ($VMTemplate in $VMTemplates)
{
	Write-Host Working on $VMTemplate.Name properties..
 
	$SetVMTemplate = $VMTemplate | Set-SCVMTemplate -Domain $Domain -DomainJoinCredential $DomainJoinCredential
}

Welcome to anyone who offers more backup options to this script via contact button. Thanks for your contribution.