-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate-vCDObject.ps1
2440 lines (2201 loc) · 255 KB
/
migrate-vCDObject.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
<#
.SYNOPSIS
This script is used to migrate vCloud Director objects from one vCD instance to another. It can read from XML files, or directly from a vCD instance. Objects can be migrated individually, or in bulk (by migrating Organizations). Please read the full description for limitations.
.DESCRIPTION
The following objects can be migrated with this script: External Networks, Organizations, Users (passwords will need to be reset) and Roles, OrgVdcs, Edge Gateways (and their service configuration), OrgVdc Networks.
The following objects and attributes are NOT migrated: Catalogs, Catalog Items, vApps (and their associated objects such as vApp Networks). Metadata is NOT migrated for any object.
The script has the following limitations:
(1)when importing Organizations, there can be only one EdgeGateway per OrgVdc. If that is not the case, you will need to migrate Edge Gateways one by one before being able to finish an Organization migration.
(2)external networks must be individually migrated first, or Edge Gateways will not be migrated.
(3)when importing Organizations, all child objects are attempted to be created. This is not true for any other object type.
(4)this script has only been tested with a vCD 5.6 as source and vCD 8.10 as target.
(5)if objects already exist, the script just skips creation. It will NOT delete the object and re-create it. The only exception is when re-applying EdgeGateway services configuration with the -gwservices parameter.
(6)when migrating an OrgVdc, the *any storage policy must exist on the ProviderVdc.
(7)when migrating an Organization from a source vCD instance, all supported child objects will be created automatically. When migrating from XML with -import, only the Organization object is created.
The script will prompt you for any required parameters. If you want to import from XML, you will need to specify -import.
.PARAMETER help
Displays a help message (seriously, what did you think this was?)
.PARAMETER history
Displays a release history for this script (provided the editors were smart enough to document this...)
.PARAMETER log
Specifies that you want the output messages to be written in a log file as well as on the screen.
.PARAMETER debugme
Turns off SilentlyContinue on unexpected error messages.
.PARAMETER sourcevcd
FQDN or IP address of the source vCloud Director instance from which objects will be read.
.PARAMETER targetvcd
FQDN or IP address of the target vCloud Director instance to which objects will be written.
.PARAMETER import
Full path to the XML file describing the object you want to migrate/import to the target vCD instance. This is exclusive with sourcevcd; use either but not both. XML file can be a vCD object export (using the REST API) or a properly formatted XML file as documented in the vCD REST API documentation.
.PARAMETER objecttype
This is only required with sourcevcd. It specifies the type of object you are trying to migrate. This can be Organization, OrgVdc, ExternalNetwork, AdminUser, OrgVdcNetwork or EdgeGateway.
.PARAMETER objectname
This is the name of the object you are trying to migrate as displayed on the source vCD instance (exp: the organization name).
.PARAMETER gwservices
Use this switch if you want to apply EdgeGateway services configuration only and not create the whole EdgeGateway object.
.PARAMETER userpassword
Specify a default password here which will be used for any AdminUser object migrated. This is useful when imigrating Organizations which have multiple users. If you do not specify this, you will be prompted for a new password for each user that is migrated.
.PARAMETER rename
Specifies that you want to rename objects. Applies only if you are importing an organization from a source vCD instance, and will prompt you to rename the following objects: organization, orgVdc and Edge Gateway.
.PARAMETER NewOrgName
When using -rename, specifies the new name of the Organization object.
.PARAMETER NewOrgVdcName
When using -rename, specifies the new name of the OrgvDC object.
.PARAMETER NewEdgeName
When using -rename, specifies the new name of the Edge Gateway object.
.PARAMETER pvDC
Specifies the name of the Provider vDC you want to use for the OrgVdc when importing an entire Organization structure from a source vCD instance.
.EXAMPLE
Import an Organization from a source vCD:
PS> .\migrate-vCDObject.ps1 -sourcevcd vcloud1.acme.com -targetvcd vcloud2.acme.com -objectType Organization -objectName AcmeCorp -userPassword "AcmeCorp/4u"
.EXAMPLE
Import an EdgeGateway from an XML file:
PS> .\migrate-vCDObject.ps1 -targetvcd vcloud2.acme.com -import ".\AcmeCorp\Edge Gateways\AcmeCorp-Edge.xml"
.EXAMPLE
Only re-apply the EdgeGateway service configuration from a source vCD:
PS> .\migrate-vCDObject.ps1 -sourcevcd vcloud1.acme.com -targetvcd vcloud2.acme.com -objectType EdgeGateway -objectName AcmeCorp-Edge -gwservices
.LINK
http://www.nutanix.com/services
.NOTES
Author: Stephane Bourdeaud ([email protected])
Revision: November 17th 2016
#>
#region Parameters
######################################
## parameters and initial setup ##
######################################
#let's start with some command line parsing
Param
(
#[parameter(valuefrompipeline = $true, mandatory = $true)] [PSObject]$myParam1,
[parameter(mandatory = $false)] [switch]$help,
[parameter(mandatory = $false)] [switch]$history,
[parameter(mandatory = $false)] [switch]$log,
[parameter(mandatory = $false)] [switch]$debugme,
[parameter(mandatory = $false)] [string]$sourcevcd,
[parameter(mandatory = $false)] [string]$targetvcd,
[parameter(mandatory = $false)] [string]$import,
[parameter(mandatory = $false)] [string]$objectType,
[parameter(mandatory = $false)] [string]$objectName,
[parameter(mandatory = $false)] [switch]$gwservices,
[parameter(mandatory = $false)] [string]$userPassword,
[parameter(mandatory = $false)] [switch]$rename,
[parameter(mandatory = $false)] [string]$newOrgName,
[parameter(mandatory = $false)] [string]$newOrgVdcName,
[parameter(mandatory = $false)] [string]$newEdgeName,
[parameter(mandatory = $false)] [string]$pvDC
)
#endregion
#region Functions
########################
## main functions ##
########################
#this function is used to output log data
Function OutputLogData {
#input: log category, log message
#output: text to standard output
<#
.SYNOPSIS
Outputs messages to the screen and/or log file.
.DESCRIPTION
This function is used to produce screen and log output which is categorized, time stamped and color coded.
.NOTES
Author: Stephane Bourdeaud
.PARAMETER myCategory
This the category of message being outputed. If you want color coding, use either "INFO", "WARNING", "ERROR" or "SUM".
.PARAMETER myMessage
This is the actual message you want to display.
.EXAMPLE
PS> OutputLogData -mycategory "ERROR" -mymessage "You must specify a cluster name!"
#>
[CmdletBinding()]
param
(
[string] $category,
[string] $message
)
begin
{
$myvarDate = get-date
$myvarFgColor = "Gray"
switch ($category)
{
"INFO" {$myvarFgColor = "Green"}
"WARNING" {$myvarFgColor = "Yellow"}
"ERROR" {$myvarFgColor = "Red"}
"SUM" {$myvarFgColor = "Magenta"}
}
}
process
{
Write-Host -ForegroundColor $myvarFgColor "$myvarDate [$category] $message"
if ($log) {Write-Output "$myvarDate [$category] $message" >>$myvarOutputLogFile}
}
end
{
Remove-variable category
Remove-variable message
Remove-variable myvarDate
Remove-variable myvarFgColor
}
}#end function OutputLogData
# Configure session to accept untrusted SSL certs
function ignoreSSL {
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
}
#figure out a REST URL
function getRESTURL {
#input: lookup, rel, type, sessionId, object
#output: Url string
<#
.SYNOPSIS
Use this function to lookup REST Urls from a vCloud Director instance.
.DESCRIPTION
The function uses a lookup source Url and looks in the Link section of the REST response to identify a specific Url matching a given rel and type.
.NOTES
Author: Stephane Bourdeaud
.PARAMETER lookup
This the lookup Url (as specified in the vCD REST API documentation).
.PARAMETER rel
This is the rel you want to lookup.
.PARAMETER type
This is the type you want to lookup.
.PARAMETER sessionId
This is the sessionId you want to use for the REST lookup.
.PARAMETER object
This is the type of object returned by the lookup URL within which we will examine the Link section for the given rel and type.
.EXAMPLE
Lookup the Url for adding organizations using a sessionId from an object which is the result of the Connect-CiServer cmdlet:
getRESTUrl -lookup "https://vcloud.local/api/admin") -type "application/vnd.vmware.admin.organization+xml" -rel "add" -sessionId $vcdConnect.SessionId -Object VCloud
#>
[CmdletBinding()]
#region param
param
(
[string] $Lookup, #this is the URL used to lookup the next URL (from documentation)
[string] $Rel, #this is the Rel type (add, delete, etc; also specified in the documentation)
[string] $Type, #this is the content type (again, see the documentation)
[string] $SessionId, #this is the web session Id to use to perform the lookup
[string] $Object #this is the type of object we're looking into
)
#endregion
begin {
#prepare headers for our lookup request
$RESTHeaders = @{"Accept"="application/*+xml;version=20.0"}
$RESTHeaders += @{"x-vcloud-authorization"=$SessionId}
}#end begin
process {
#get the XML from the lookup URL
OutputLogData -category "INFO" -message "Accessing URL $Lookup..."
try {
$myvarRESTResponse = Invoke-RestMethod -Uri $Lookup -Headers $RESTHeaders -Method Get -ErrorAction Stop
}
catch {
OutputLogData -category "ERROR" -message "$($_.Exception.Message)"
OutputLogData -category "ERROR" -message "Could not access URL $Lookup, exiting."
Exit
}
OutputLogData -category "INFO" -message "Successfully accessed URL $Lookup, searching for link with rel $Rel and type $Type ..."
#walk thru the Link items until we find our Rel type and Content type
ForEach ($Link in $myvarRESTResponse.$Object.Link) {
if (($Link.rel -eq $Rel) -and ($Link.type -eq $Type)) {
$myvarRESTPOSTUrl = $Link.Href
OutputLogData -category "INFO" -message "Found $myvarRESTPOSTUrl with rel $Rel and type $Type"
break
}#end if match rel and type
}#end foreach link
if (!$myvarRESTPOSTUrl) {
OutputLogData -category "ERROR" -message "Could not find a URL that matches $Rel and $Type at $Lookup! Exiting."
Remove-Variable -ErrorAction SilentlyContinue
Exit
}
}#end process
end {
Remove-Variable Lookup
Remove-Variable Rel
Remove-Variable Type
Remove-Variable SessionId
Remove-Variable RESTHeaders
Remove-Variable Object
#return the URL
return $myvarRESTPOSTUrl
}#end
}#end function
#connect to a vCD server
function connectVcd {
#input: vcd, credentials
#output: connection information
<#
.SYNOPSIS
Connect to a vCD instance using Connect-CiServer with error checking and handling.
.DESCRIPTION
Connect to a vCD instance using Connect-CiServer with error checking and handling.
.NOTES
Author: Stephane Bourdeaud
.PARAMETER vcd
This the FQDN or IP of the vCD server you are trying to connect to.
.PARAMETER credentials
This is a system crdentials object obtained with Get-Credentials.
.EXAMPLE
connectVcd -Credentials (get-credentials) -Vcd vcloud.local
#>
[CmdletBinding()]
#region Param
param
(
[string] $Vcd,
[System.Management.Automation.PSCredential] $Credentials
)
#endregion
begin {
}#end begin
process {
OutputLogData -category "INFO" -message "Connecting to the vCloud Director instance $Vcd..."
if (!$myvarVcdConnect.IsConnected) {
try {
$myvarVcdConnect = Connect-CIServer -Server $Vcd -Org 'system' -Credential $Credentials -ErrorAction Stop
}
catch {
OutputLogData -category "ERROR" -message "$($_.Exception.Message)"
OutputLogData -category "ERROR" -message "Could not connect to the vCloud Director $Vcd (credentials correct?), exiting."
Exit
}
}#endif connected?
OutputLogData -category "INFO" -message "Connected to the vCloud Director $Vcd : OK"
}#end process
end {
Remove-Variable Vcd
Remove-Variable Credentials
return $myvarVcdConnect
}#end
}#end function
#get an OrgVdc object XML description
function getVcdOrgVdc {
#input: org, orgVdcName, vcdConnect
#output: OrgVdc XML description
<#
.SYNOPSIS
Get the XML description of a given OrgVdc object.
.DESCRIPTION
Get the XML description of a given OrgVdc object. The object is searched with Get-OrgVdc, then accessed thru its Url using REST.
.NOTES
Author: Stephane Bourdeaud
.PARAMETER orgVdcName
String containing the OrgVdc name as displayed in vCD.
.PARAMETER vcdConnect
A connection object obtained from Connect-CiServer.
.EXAMPLE
getVcdOrgVdc -orgVdcName AcmeOrg_Vdc -vcdConnect (Connect-CiServer -Server vcloud.local)
#>
[CmdletBinding()]
#region param
param
(
[string] $org,
[string] $orgVdcName,
$vcdConnect
)
#endregion
begin {
}#end begin
process {
$myvarOrgVdc = Get-Org -Server $vcdConnect.Name -Name $org | Get-OrgVdc -Server $vcdConnect.Name -Name $orgVdcName #using get-orgvdc as search-cloud does not correctly return OrgVdcs...
OutputLogData -category "INFO" -message "Processing $($myvarOrgVdc.Name)..."
$myvarUrl = $myvarOrgVdc.Href #this is the Url we'll use to retrieve the XML description
#preparing REST request headers
$myvarHeaders = @{"Accept"="application/*+xml;version=5.1"}
$myvarHeaders += @{"x-vcloud-authorization"=$vcdConnect.SessionId}
#retrieveing the XML description for that OrgVdc
$myvarOrgVdcResponse = Invoke-RestMethod -Uri $myvarUrl -Headers $myvarHeaders -Method Get
}#end process
end {
return $myvarOrgVdcResponse
}#end
}#end function
#get an OrgVdcNetwork object XML description
function getVcdOrgVdcNetwork {
#input: orgVdcNetworkName, vcdConnect
#output: OrgVdcNetwork XML description
<#
.SYNOPSIS
Get the XML description of a given OrgVdcNetwork object.
.DESCRIPTION
Get the XML description of a given OrgVdcNetwork object. The object is searched with Get-OrgVdcNetwork, then accessed thru its Url using REST.
.NOTES
Author: Stephane Bourdeaud
.PARAMETER orgVdcNetworkName
String containing the OrgVdcNetwork name as displayed in vCD.
.PARAMETER vcdConnect
A connection object obtained from Connect-CiServer.
.EXAMPLE
getVcdOrgVdcNetwork -orgVdcNetworkName AcmeOrg_VdcNetwork1 -vcdConnect (Connect-CiServer -Server vcloud.local)
#>
[CmdletBinding()]
#region param
param
(
[string] $orgName,
[string] $orgVdcName,
[string] $orgVdcNetworkName,
$vcdConnect
)
#endregion
begin {
}#end begin
process {
$myvarOrgVdcNetwork = Get-Org -Server $vcdConnect.Name -Name $orgName | Get-OrgVdc -Server $vcdConnect.Name -Name $orgVdcName | Get-OrgVdcNetwork -Server $vcdConnect.Name -Name $orgVdcNetworkName #search-cloud does not accurately return OrgVdcNetwork objects, so using get-orgvdcnetwork instead
OutputLogData -category "INFO" -message "Processing OrgVdcNetwork $($myvarOrgVdcNetwork.Name)..."
$myvarUrl = $myvarOrgVdcNetwork.Href #this is the Url for that OrgVdcNetwork object which we'll use in our REST request
#preparing REST headers
$myvarHeaders = @{"Accept"="application/*+xml;version=5.5"}
$myvarHeaders += @{"x-vcloud-authorization"=$vcdConnect.SessionId}
#using REST to retrieve the XML description for that object
$myvarOrgVdcNetworkResponse = Invoke-RestMethod -Uri $myvarUrl -Headers $myvarHeaders -Method Get
}#end process
end {
return $myvarOrgVdcNetworkResponse
}#end
}#end function
#get any other type of vCloud Director object XML description
function getVcdObject {
#input: type, name, vcd, href
#output: vCD object XML description
<#
.SYNOPSIS
Get the XML description of a given vCloud Director object.
.DESCRIPTION
Get the XML description of a given vCloud Director object. The object is searched with Search-Cloud, then accessed using REST to obtain an XML description.
.NOTES
Author: Stephane Bourdeaud
.PARAMETER type
This the type of the object you want to get an XML for. Any type that works with Search-Cloud is valid here.
.PARAMETER name
This is the name of the object as displayed in vCD.
.PARAMETER vcdConnect
This is the connnection information to vCD as obtained from a Connect-CiServer command.
.PARAMETER href
This is the href of the object you want to lookup. If you specify an href, you do not need to specify a name and type, but you do need to specify an href type.
.PARAMETER hrefType
This is the type of the object you want to lookup in REST API format such as "application/vnd.vmware.admin.user+xml".
.EXAMPLE
getVcdObject -name AcmeOrg_EGW -type EdgeGateway -vcdConnect (Connect-CiServer -Server vcloud.acme.com)
#>
[CmdletBinding()]
#region param
param
(
[string] $type,
[string] $name,
$vcdConnect,
[string] $href,
[string] $hreftype
)
#endregion
begin {
}#end begin
process {
if (!$href) {#do we have an href?
#Search object
try {
$myvarObject = Search-Cloud -Server $vcdConnect.Name -QueryType $type -Name $name -ErrorAction Stop
}
catch {
[System.Windows.Forms.MessageBox]::Show("Exception: " + $_.Exception.Message + " - Failed item:" + $_.Exception.ItemName ,"Error.",0,[System.Windows.Forms.MessageBoxIcon]::Exclamation)
OutputLogData -category "ERROR" -message "$type with name $name not found"
return $false
}
finally {
$myvarObjectView = $myvarObject | Get-CIView
$href = $myvarObjectView.href
$hreftype = $myvarObjectView.Type
}
}#endif href
if ($href) {
#Getting the XML description using REST
if ($type -and $name) {OutputLogData -category "INFO" -message "Setting up connection to REST API for $type $name..."}
else {OutputLogData -category "INFO" -message "Setting up connection to REST API $href..."}
$myvarWebclient = New-Object system.net.webclient
$myvarWebclient.Headers.Add("x-vcloud-authorization",$vcdConnect.SessionId)
$myvarwebclient.Headers.Add("accept",$hrefType + ";version=5.1")
if ($type -and $name) {OutputLogData -category "INFO" -message "Retrieving details for $type $name..."}
else {OutputLogData -category "INFO" -message "Retrieving $href details..."}
[XML]$myvarObjectXML = $myvarwebclient.DownloadString($href)
}#endif href
else {
OutputLogData -category "WARNING" -message "$type with name $name not found"
}#endelse href
}#end process
end {
return $myvarObjectXML
}#end
}#end function
#function create a vCD organization object from an XML description
function createVcdOrg {
#input: OrgXML, vcdConnect
#output: REST response for object creation
<#
.SYNOPSIS
Create a vCloud Director organization object from an XML description.
.DESCRIPTION
Create a vCloud Director organization object from an XML description. This does not include any child objects.
.NOTES
Author: Stephane Bourdeaud
.PARAMETER OrgXML
This the XML description of the Organization object to create.
.PARAMETER vcdConnect
This is the connection information for the vCD instance where you want to create the object. This is obtained from a Connect-CiServer.
.EXAMPLE
createVcdOrg -OrgXML $AcmeOrgXmlObject -vcdConnect (Connect-CiServer -Server vcloud.acme.com)
#>
[CmdletBinding()]
#region param
param
(
[Xml] $OrgXML,
$vcdConnect
)
#endregion
begin {
}#end begin
process {
#update the organization name if nessecary
if ($rename) {
$OrgXML.AdminOrg.name = $myvarNewOrgName
}#endif rename
#ok, we're ready to create the organization using the REST API, let's prepare headers and the XML body
$myvarRESTContentType = "application/vnd.vmware.admin.organization+xml"
$myvarRESTXMLBody = '<?xml version="1.0" encoding="UTF-8"?>' + $nl
$myvarRESTXMLBody += $OrgXML.AdminOrg.OuterXml | Format-Xml #that takes care of the XML body
$myvarRESTHeaders = @{"Accept"="application/*+xml;version=20.0"}
$myvarRESTHeaders += @{"Content-Type"=$myvarRESTContentType}
$myvarRESTHeaders += @{"x-vcloud-authorization"=$vcdConnect.SessionId} #that takes care of the headers
#we've got the content properly formatted, let's prepare the URL
$myvarRESTUrl = getRESTUrl -lookup $($vcdConnect.HRef + "admin") -type $myvarRESTContentType -rel "add" -sessionId $vcdConnect.SessionId -Object VCloud
#ok, we're ready to roll with the REST request
OutputLogData -category "INFO" -message "Creating the organization..."
try {
$myvarRESTResponse = Invoke-RestMethod -Uri $myvarRESTUrl -Headers $myvarRESTHeaders -Method Post -Body $myvarRESTXMLBody -ErrorAction Stop
}
catch {
OutputLogData -category "ERROR" -message "$($_.Exception.Message)"
OutputLogData -category "ERROR" -message "Could not create the organization, exiting."
$myvarRESTFullError = RESTFailureHandling
if ($myvarRESTFullError -match '(?<= ] )(.+)(?=" minorErrorCode)') {
$myError = $matches[0]
OutputLogData -category "ERROR" -message "$myError"
} else {OutputLogData -category "ERROR" -message "$myvarRESTFullError"}
Exit
}
OutputLogData -category "INFO" -message "Successfully created the organization."
}#end process
end {
}#end
}#end function
#function create a user object in a vCD organization
function createVcdUser {
#input: orgName, vcdConnect, userXML
#output: REST response for object creation
<#
.SYNOPSIS
Create a vCloud Director user object from an XML description.
.DESCRIPTION
Create a vCloud Director user object from an XML description. This does not include any child or dependent objects.
.NOTES
Author: Stephane Bourdeaud
.PARAMETER orgName
This the name of the Organization you want the user to belong to.
.PARAMETER userXML
This the XML description of the user object to create.
.PARAMETER vcdConnect
This is the connection information for the vCD instance where you want to create the object. This is obtained from a Connect-CiServer.
.EXAMPLE
createVcdUser -orgName AcmeOrg -XMLObject $UserXmlObject -vcdConnect (Connect-CiServer -Server vcloud.acme.com)
#>
[CmdletBinding()]
#region param
param
(
[string] $OrgName,
$vcdConnect,
[Xml] $userXML
)
#endregion
begin {
}#end begin
process {
#region XML Editing
#we need to know which organization this user belongs to
if (!$OrgName) {$OrgName = Read-Host "Enter the name of the Organization where this user will be created"}#endif no org
try {
$myvarOrgView = Search-Cloud -Server $vcdConnect.Name -QueryType Organization -Name $OrgName -ErrorAction Stop | Get-CIView
}
catch {
OutputLogData -category "ERROR" -message "$($_.Exception.Message)"
OutputLogData -category "ERROR" -message "Could not find the Organization $OrgName, exiting."
Exit
}
$myvarOrgURL = $myvarOrgView.Href
#we need to update the Role href in the XML description
$myvarRoleView = Search-Cloud -Server $vcdConnect.Name -QueryType Role -Name $userXML.User.Role.name -ErrorAction Stop | Get-CIView
$myvarRoleUrl = $myvarRoleView.Href
$userXML.User.Role.href = $myvarRoleUrl
#finally, we need to prompt for the password and add it to the XML description
if (!$userPassword) {
$myvarPasswordSecureString = Read-Host "Please enter the desired password for user $($userXML.User.Name)" -AsSecureString
$myvarPassword = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($myvarPasswordSecureString) #decoding password as REST API wants unsecure string, phase 1/2
$myvarPasswordString = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($myvarPassword) #decoding password as REST API wants unsecure string, phase 2/2
}#endif userPassword
else {
$myvarPasswordString = $userPassword
}#endelse userPassword
($myvarXMLElement = $userXML.CreateElement("Password",$userXML.User.xmlns)) | Out-Null #let's create a new password element in the XML description in the same namespace as User
($userXML.User.InsertAfter($myvarXMLElement,$userXML.User.Role)) | Out-Null #we now insert the new element after the Role element
($userXML.User.Password = $myvarPasswordString) | Out-Null #and write the unscrambled password in it
Remove-Variable myvarPasswordString #we immediately remove the unscrambled password from memory for security's sake
Remove-Variable myvarPassword
#endregion
#region REST POST
#ok, we're ready to create the organization using the REST API, let's prepare headers and the XML body
$myvarRESTContentType = "application/vnd.vmware.admin.user+xml"
$myvarRESTXMLBody = '<?xml version="1.0" encoding="UTF-8"?>' + $nl
$myvarRESTXMLBody += $userXML.User.OuterXml | Format-Xml #that takes care of the XML body
$myvarRESTHeaders = @{"Accept"="application/*+xml;version=20.0"}
$myvarRESTHeaders += @{"Content-Type"=$myvarRESTContentType}
$myvarRESTHeaders += @{"x-vcloud-authorization"=$vcdConnect.SessionId} #that takes care of the headers
#we've got the content properly formatted, let's prepare the URL
$myvarRESTUrl = getRESTUrl -lookup $myvarOrgUrl -type $myvarRESTContentType -rel "add" -sessionId $vcdConnect.SessionId -Object AdminOrg
#ok, we're ready to roll with the REST request
OutputLogData -category "INFO" -message "Creating the user $($userXML.User.Name)..."
try {
$myvarRESTResponse = Invoke-RestMethod -Uri $myvarRESTUrl -Headers $myvarRESTHeaders -Method Post -Body $myvarRESTXMLBody -ErrorAction Stop
}
catch {
OutputLogData -category "ERROR" -message "$($_.Exception.Message)"
OutputLogData -category "ERROR" -message "Could not create the user $($userXML.User.Name), exiting."
$myvarRESTFullError = RESTFailureHandling
if ($myvarRESTFullError -match '(?<= ] )(.+)(?=" minorErrorCode)') {
$myError = $matches[0]
OutputLogData -category "ERROR" -message "$myError"
} else {OutputLogData -category "ERROR" -message "$myvarRESTFullError"}
Exit
}
OutputLogData -category "INFO" -message "Successfully created the user $($userXML.User.Name)."
#endregion
}#end process
end {
}#end
}#end function
#function create a role object
function createVcdRole {
#input: vcdConnect, roleXML
#output: REST response for object creation
<#
.SYNOPSIS
Create a vCloud Director role object from an XML description.
.DESCRIPTION
Create a vCloud Director role object from an XML description.
.NOTES
Author: Stephane Bourdeaud
.PARAMETER roleXML
This the XML description of the role object to create.
.PARAMETER vcdConnect
This is the connection information for the vCD instance where you want to create the object. This is obtained from a Connect-CiServer.
.EXAMPLE
createVcdRole -roleXML $RoleXmlObject -vcdConnect (Connect-CiServer -Server vcloud.acme.com)
#>
[CmdletBinding()]
#region param
param
(
$vcdConnect,
[Xml] $roleXML
)
#endregion
begin {
}#end begin
process {
#region XML Editing
#we need to know which organization this user belongs to
if (!$OrgName) {$OrgName = Read-Host "Enter the name of the Organization where this user will be created"}#endif no org
try {
$myvarOrgView = Search-Cloud -Server $vcdConnect.Name -QueryType Organization -Name $OrgName -ErrorAction Stop | Get-CIView
}
catch {
OutputLogData -category "ERROR" -message "$($_.Exception.Message)"
OutputLogData -category "ERROR" -message "Could not find the Organization $OrgName, exiting."
Exit
}
$myvarOrgURL = $myvarOrgView.Href
#we need to update the Role href in the XML description
$myvarRoleView = Search-Cloud -Server $vcdConnect.Name -QueryType Role -Name $roleXML.User.Role.name -ErrorAction Stop | Get-CIView
$myvarRoleUrl = $myvarRoleView.Href
$roleXML.User.Role.href = $myvarRoleUrl
#finally, we need to prompt for the password and add it to the XML description
if (!$userPassword) {
$myvarPasswordSecureString = Read-Host "Please enter the desired password for user $($XMLObject.User.Name)" -AsSecureString
$myvarPassword = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($myvarPasswordSecureString) #decoding password as REST API wants unsecure string, phase 1/2
$myvarPasswordString = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($myvarPassword) #decoding password as REST API wants unsecure string, phase 2/2
}#endif userPassword
else {
$myvarPasswordString = $userPassword
}#endelse userPassword
($myvarXMLElement = $roleXML.CreateElement("Password",$roleXML.User.xmlns)) | Out-Null #let's create a new password element in the XML description in the same namespace as User
($roleXML.User.InsertAfter($myvarXMLElement,$roleXML.User.Role)) | Out-Null #we now insert the new element after the Role element
($roleXML.User.Password = $myvarPasswordString) | Out-Null #and write the unscrambled password in it
Remove-Variable myvarPasswordString #we immediately remove the unscrambled password from memory for security's sake
Remove-Variable myvarPassword
#endregion
#region REST POST
#ok, we're ready to create the role using the REST API, let's prepare headers and the XML body
$myvarRESTContentType = "application/vnd.vmware.admin.role+xml"
$myvarRESTXMLBody = '<?xml version="1.0" encoding="UTF-8"?>' + $nl
$myvarRESTXMLBody += $roleXML.Role.OuterXml | Format-Xml #that takes care of the XML body
$myvarRESTHeaders = @{"Accept"="application/*+xml;version=20.0"}
$myvarRESTHeaders += @{"Content-Type"=$myvarRESTContentType}
$myvarRESTHeaders += @{"x-vcloud-authorization"=$vcdConnect.SessionId} #that takes care of the headers
#we've got the content properly formatted, let's prepare the URL
$myvarRESTUrl = $vcdConnect.ServiceUri.AbsoluteUri + "admin/roles"
#ok, we're ready to roll with the REST request
OutputLogData -category "INFO" -message "Creating the role $($roleXML.Role.Name)..."
try {
$myvarRESTResponse = Invoke-RestMethod -Uri $myvarRESTUrl -Headers $myvarRESTHeaders -Method Post -Body $myvarRESTXMLBody -ErrorAction Stop
}
catch {
OutputLogData -category "ERROR" -message "$($_.Exception.Message)"
OutputLogData -category "ERROR" -message "Could not create the role $($roleXML.Role.Name), exiting."
$myvarRESTFullError = RESTFailureHandling
if ($myvarRESTFullError -match '(?<= ] )(.+)(?=" minorErrorCode)') {
$myError = $matches[0]
OutputLogData -category "ERROR" -message "$myError"
} else {OutputLogData -category "ERROR" -message "$myvarRESTFullError"}
Exit
}
OutputLogData -category "INFO" -message "Successfully created the role $($roleXML.Role.Name)."
#endregion
}#end process
end {
}#end
}#end function
#function create an OrgVdc object
function createVcdOrgVdc {
#input: orgName, vcd, OrgVdcXML
#output: REST response for object creation
<#
.SYNOPSIS
Create a vCloud Director organization virtual datacenter object from an XML description.
.DESCRIPTION
Create a vCloud Director organization virtual datacenter object from an XML description. This does not include any child objects.
.NOTES
Author: Stephane Bourdeaud
.PARAMETER orgName
This the name of the Organizationwhere you want the OrgVdc object to be created.
.PARAMETER OrgVdcXML
This the XML description of the Organization virtual datacenter object to create.
.PARAMETER vcdConnect
This is the connection information for the vCD instance where you want to create the object. This is obtained from a Connect-CiServer.
.EXAMPLE
createVcdOrgVdc -orgName AcmeOrg -OrgVdcXML $AcmeOrgVdcXmlObject -vcdConnect (Connect-CiServer -Server vcloud.acme.com)
#>
[CmdletBinding()]
#region param
param
(
[string] $orgName,
[string] $vcd,
[Xml] $OrgVdcXML
)
#endregion
begin {
}#end begin
process {
#region XMLEditing
#OrgVdc are created in an organization and with a Provider vDC, so let's prompt the user for the org name
if (!$orgName) {$orgName = Read-Host "Please enter the name of the Organization where you want to migrate this OrgVdc"}
$myvarProvDC = Search-Cloud -Server $vcd -QueryType ProviderVdc
if ($myvarProvDC.Count -ne 1) { #is there more than 1 provider vdc defined?
if ($pvDC) {$myvarProvDCName = $pvDC} else {$myvarProvDCName = Read-Host "Please enter the name of the ProviderVdc for this OrgVdc"}
#Let's get the Provider vDC reference
OutputLogData -category "INFO" -message "Searching for Provider vDC $myvarProvDCName..."
$myvarProvDC = Search-Cloud -Server $vcd -QueryType ProviderVdc -Name $myvarProvDCName -ErrorAction Stop
$myvarProvDCView = $myvarProvDC | Get-CIView
if (!$myvarProvDCView) {
Write-Warning $($_.Exception.Message)
OutputLogData -category "ERROR" -message "Could not find Provider vDC $myvarProvDCName, exiting."
Exit
}#end if not ProvDC
OutputLogData -category "INFO" -message "Found $myvarProvDCName."
}#end if not single provider vdc
else {
$myvarProvDCView = Search-Cloud -Server $vcd -QueryType ProviderVdc | Get-CIView
}#endelse not single provider vdc
#Now we search for that Org URL on the target
OutputLogData -category "INFO" -message "Searching for organization $orgName..."
$myvarOrgView = Search-Cloud -Server $vcd -QueryType Organization -Name $orgName -ErrorAction Stop | Get-CIView
if (!$myvarOrgView) {
Write-Warning $($_.Exception.Message)
OutputLogData -category "ERROR" -message "Could not find Organization $orgName, exiting."
Exit
}#end if not Org
OutputLogData -category "INFO" -message "Found $orgName."
$myvarOrgURL = $myvarOrgView.Href
$myvarProvDCURL = $myvarProvDCView.Href
#endregion
#region XML to VimAutomation.Cloud.Views.AdminVdc translation
#there seems to be a bug in vCD 8.10 REST API for OrgVdc creation, so instead we are going to translate the XML into native PowerCLI object
$myvarAdminVdcObject = New-Object VMware.VimAutomation.Cloud.Views.AdminVdc
#the two items below are customizable using the static variables in the variables region of the script
if ($ResourceGuaranteedMemory -eq "source") {$myvarAdminVdcObject.ResourceGuaranteedMemory = $orgVdcXML.AdminVdc.ResourceGuaranteedMemory} else {$myvarAdminVdcObject.ResourceGuaranteedMemory = $ResourceGuaranteedMemory}
if ($ResourceGuaranteedCpu -eq "source") {$myvarAdminVdcObject.ResourceGuaranteedCpu = $orgVdcXML.AdminVdc.ResourceGuaranteedCpu} else {$myvarAdminVdcObject.ResourceGuaranteedCpu = $ResourceGuaranteedCpu}
$myvarAdminVdcObject.VCpuInMhz = $orgVdcXML.AdminVdc.VCpuInMhz
$myvarAdminVdcObject.IsThinProvision = $orgVdcXML.AdminVdc.IsThinProvision
$myvarAdminVdcObject.UsesFastProvisioning = $orgVdcXML.AdminVdc.UsesFastProvisioning
$myvarAdminVdcObject.AllocationModel = $orgVdcXML.AdminVdc.AllocationModel
$myvarAdminVdcObject.StorageCapacity = New-Object VMware.VimAutomation.Cloud.Views.CapacityWithUsage
$myvarAdminVdcObject.StorageCapacity.Units = "MB"
$myvarAdminVdcObject.StorageCapacity.Limit = 0
$myvarAdminVdcObject.ComputeCapacity = New-Object VMware.VimAutomation.Cloud.Views.ComputeCapacity
$myvarAdminVdcObject.ComputeCapacity.Cpu = New-Object VMware.VimAutomation.Cloud.Views.CapacityWithUsage
$myvarAdminVdcObject.ComputeCapacity.Cpu.Units = "MHz"
$myvarAdminVdcObject.ComputeCapacity.Cpu.Limit = $orgVdcXML.AdminVdc.ComputeCapacity.Cpu.Limit
$myvarAdminVdcObject.ComputeCapacity.Cpu.Allocated = $orgVdcXML.AdminVdc.ComputeCapacity.Cpu.Allocated
$myvarAdminVdcObject.ComputeCapacity.Memory = New-Object VMware.VimAutomation.Cloud.Views.CapacityWithUsage
$myvarAdminVdcObject.ComputeCapacity.Memory.Units = "MB"
$myvarAdminVdcObject.ComputeCapacity.Memory.Limit = $orgVdcXML.AdminVdc.ComputeCapacity.Memory.Limit
$myvarAdminVdcObject.ComputeCapacity.Memory.Allocated = $orgVdcXML.AdminVdc.ComputeCapacity.Memory.Allocated
$myvarAdminVdcObject.NicQuota = $orgVdcXML.AdminVdc.NicQuota
$myvarAdminVdcObject.NetworkQuota = $orgVdcXML.AdminVdc.NetworkQuota
$myvarAdminVdcObject.UsedNetworkCount = $orgVdcXML.AdminVdc.UsedNetworkCount
$myvarAdminVdcObject.VmQuota = $orgVdcXML.AdminVdc.VmQuota
$myvarAdminVdcObject.IsEnabled = $orgVdcXML.AdminVdc.IsEnabled
$myvarAdminVdcObject.VdcStorageProfiles = New-Object VMware.VimAutomation.Cloud.Views.VdcStorageProfiles
$myvarAdminVdcObject.VdcStorageProfiles.VdcStorageProfile[0] = New-Object VMware.VimAutomation.Cloud.Views.VdcStorageProfiles.Reference
$myvarAdminVdcObject.Name = $myvarNewOrgVdcName
$myvarAdminVdcObject.Description = $orgVdcXML.AdminVdc.Description
#$myvarAdminVdcObject.ResourceEntities
#$myvarAdminVdcObject.AvailableNetworks
#$myvarAdminVdcObject.Tasks
#$myvarAdminVdcObject.Id
#$myvarAdminVdcObject.OperationKey
#$myvarAdminVdcObject.Client
#$myvarAdminVdcObject.Href
#$myvarAdminVdcObject.Type
#$myvarAdminVdcObject.Link
#$myvarAdminVdcObject.AnyAttr
#$myvarAdminVdcObject.VCloudExtension
#$myvarAdminVdcObject.VendorServices
#$myvarAdminVdcObject.OverCommitAllowed
#$myvarAdminVdcObject.Status
#$myvarAdminVdcObject.Capabilities
$myvarProviderVdc = Get-ProviderVdc -Server $vcd -Name $myvarProvDCView.Name
$myvarProviderVdcRef = New-Object VMware.VimAutomation.Cloud.Views.Reference
$myvarProviderVdcRef.Href = $myvarProviderVdc.Href
$myvarAdminVdcObject.ProviderVdcReference =$myvarProviderVdcRef
####Add support for multiple network pools here
$myvarNetworkPool = Get-NetworkPool -Server $vcd -ProviderVdc $myvarProvDCView.Name
if ($myvarNetworkPool.Count -gt 1) { #we have more than one network pool
#OutputLogData -category "ERROR" -message "There is more than one Network Pool which this script does not deal with: exiting"
#Exit
$myvarNetworkPoolName = Read-Host "Please enter the name of the network pool for this OrgVdc"
$myvarNetworkPool = Get-NetworkPool -Server $vcd -Name $myvarNetworkPoolName
}
$myvarNetworkPoolRef = New-Object VMware.VimAutomation.Cloud.Views.Reference
$myvarNetworkPoolRef.Href = $myvarNetworkPool.Href
$myvarAdminVdcObject.NetworkPoolReference = $myvarNetworkPoolRef
$myvarOrgED = (Get-Org -Server $vcd -Name $orgName).ExtensionData
OutputLogData -category "INFO" -message "Creating the OrgVdc $myvarNewOrgVdcName for $orgName..."
try
{
$myvarOrgED.CreateVdc($myvarAdminVdcObject) | Out-Null
}
catch
{
OutputLogData -category "ERROR" -message "$($_.Exception.Message)"
OutputLogData -category "ERROR" -message "Could not create the OrgVdc $myvarNewOrgVdcName for $orgName : exiting."
Exit
}
OutputLogData -category "INFO" -message "Successfully created the OrgVdc $myvarNewOrgVdcName for $orgName."
#endregion
#region Dealing with storage profiles
# Find the Storage Profiles in the Provider vDC to be added to the Org vDC
OutputLogData -category "INFO" -message "Waiting for 20 seconds before configuring storage policies..."
Start-Sleep -Seconds 20
OutputLogData -category "INFO" -message "Getting Storage Profiles from Provider vDC..."
try {
$pvDCProfiles = search-cloud -Server $vcd -QueryType ProviderVdcStorageProfile -ErrorAction Stop | where {$_.ProviderVdc -eq $myvarProvDC.Id} | Get-CIView
}
catch {
[System.Windows.Forms.MessageBox]::Show("Exception: " + $_.Exception.Message + " - Failed item:" + $_.Exception.ItemName ,"Error.",0,[System.Windows.Forms.MessageBoxIcon]::Exclamation)
OutputLogData -category "ERROR" -message "Could not retrieve ProviderVdcStorageProfile from $vcd."
return $false
}
OutputLogData -category "INFO" -message "Retrieving the newly created OrgVdc object from the target..."
$myvarOrgVdcObject = Get-Org -Server $vcd -Name $orgname | Get-OrgVdc -Server $vcd -Name $myvarNewOrgVdcName
if ($pvDCProfiles) {
# Strip out any disabled Profiles
OutputLogData -category "INFO" -message "Stripping out disabled Profiles..."
$pvDCProfiles = $pvDCProfiles | where {$_.Enabled -eq $True}
# Strip out the generic * Profile
OutputLogData -category "INFO" -message "Removing the * (Any) Profile from the list of source storage capabilities..."
$pvDCProfiles = $pvDCProfiles | where {$_.Name -ne "*"}
# Loop through the collected profiles and assign them to the new Org VDC
OutputLogData -category "INFO" -message "Writing Storage Profiles to Organization vDC..."
foreach ($storProfile in $pvDCProfiles) {
# Create a new object of type VdcStorageProfileParams and fill in the parameters for the new Org vDC passing in the href of the Provider vDC Storage Profile
$spParams = new-object VMware.VimAutomation.Cloud.Views.VdcStorageProfileParams
$spParams.Limit = 1024000
$spParams.Units = "MB"
$spParams.ProviderVdcStorageProfile = $storProfile.href
$spParams.Enabled = $true
$spParams.Default = $false
# Create an UpdateVdcStorageProfiles object and put the new parameters into the AddStorageProfile element
$UpdateParams = new-object VMware.VimAutomation.Cloud.Views.UpdateVdcStorageProfiles
$UpdateParams.AddStorageProfile = $spParams
# Create the new Storage Profile entry in my test Org vDC
$myvarOrgVdcObject.ExtensionData.CreateVdcStorageProfile($UpdateParams) | Out-Null
$myvarOrgVdcObject.ExtensionData.UpdateServerData()
OutputLogData -category "INFO" -message "Added storage profile $($storProfile.Name)."
Start-Sleep -Seconds 5
}#end foreach storage profile
# Prompt user to select the default storage profile to use.
#OutputLogData -category "INFO" -message "Select the Storage Profile you want to use for the DEFAULT for this OrgVDC"
if ($pvdcProfiles.Count -gt 1) {
$DefaultProfile = Read-Host "Enter the name of the default storage profile you want to use"
}
else {
$DefaultProfile = $pvdcProfiles.Name
}
$orgvDCDefaultProfile = search-cloud -server $vcd -querytype AdminOrgVdcStorageProfile | where {($_.Name -match $($DefaultProfile)) -and ($_.VdcName -eq $myvarNewOrgVdcName)} | Get-CIView
# Set the Profile as the new default
OutputLogData -category "INFO" -message "Setting Default Storage Profile to $DefaultProfile..."
$orgvDCDefaultProfile.Default = $true
$orgvDCDefaultProfile.UpdateServerData() | Out-Null
# Get object representing the * (Any) Profile in the Org vDC
$orgvDCAnyProfile = search-cloud -server $vcd -querytype AdminOrgVdcStorageProfile | where {($_.Name -match '\*') -and ($_.VdcName -eq $myvarNewOrgVdcName)} | Get-CIView
# Disable the "* (any)" Profile
OutputLogData -category "INFO" -message "Removing the (*) Any Profile from this OrgVdc..."
$orgvDCAnyProfile.Enabled = $False
$orgvDCAnyProfile.UpdateServerData() | Out-Null
# Remove the "* (any)" profile form the Org vDC completely
$ProfileUpdateParams = new-object VMware.VimAutomation.Cloud.Views.UpdateVdcStorageProfiles
$ProfileUpdateParams.RemoveStorageProfile = $orgvDCAnyProfile.href
$myvarOrgVdcObject.extensiondata.CreatevDCStorageProfile($ProfileUpdateParams) | Out-Null
$myvarOrgVdcObject.ExtensionData.UpdateServerData()
}#endif pvDCStorageProfiles
else {
OutputLogData -category "WARNING" -message "There was no storage profiles to process!"
}#endelse pvDCStorageProfiles
OutputLogData -category "INFO" -message "Setting Thin Provisioning Option..."
$myvarOrgVdcObject | Set-OrgVdc -UseFastProvisioning $false -ThinProvisioned $true | Out-Null
#endregion
}#end process
end {
}#end
}#end function
#function create an EdgeGateway object
function createVcdEdgeGateway {
#input: orgVdcName, vcdConnect, EdgeGatewayXML
#output: REST response for object creation
<#
.SYNOPSIS
Create a vCloud Director EdgeGateway object from an XML description.
.DESCRIPTION