VMware.CfgMax.psm1

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

$Script:urlBase = "https://configmax-service.esp.vmware.com"
$Script:CfgMaxHeaders = New-Object 'System.Collections.Generic.Dictionary[String,object]'
$Script:CfgMaxHeaders.Add("Origin", "https://configmax-service.esp.vmware.com")
$Script:CfgMaxHeaders.Add("Referer", "https://configmax-service.esp.vmware.com/guest")
$Script:CfgMaxHeaders.Add("Content-Type", "application/json")

function Convert-CfgMaxRawLimit {
    param (
        $raw
    )

    $data = $raw.split('/')
    $data[0].trim('-')
}

function Add-UriQueryParam {
    param (
        [Parameter (Mandatory = $true)]
        [object]$QueryObject,
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [string[]]$QueryString
    )

    foreach ($queryToAppend in $QueryString) {
        if ( ($null -ne $QueryObject) -AND ($QueryObject.Length -gt 1) ) {
            if ($QueryObject.contains($queryToAppend)) {
                Write-Verbose "QueryObject already contains $queryToAppend. Not adding."
            }
            else {
                if ($QueryObject.StartsWith('?')) {
                    $QueryObject = $QueryObject.Substring(1) + "&" + $queryToAppend
                }
                else {
                    $QueryObject = $QueryObject + "&" + $queryToAppend
                }
            }
        }
        else {
            $QueryObject = $queryToAppend; 
        }
    }
    $QueryObject
}

function ConvertFrom-UnixTime {
    param (
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [Double]$timestamp
    )
    $EpochStart = Get-Date 1970-01-01T00:00:00
    $EpochStart = $EpochStart.AddMilliseconds($timestamp)
    $EpochStart.tostring('dd MMM yyyy')
}

function New-CfgMaxCategorySpec {
    param (
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [string]$ProductId,
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [string]$ReleaseId
    )
    $data = @{
        "prodId"     = $ProductId;
        "relId"      = $ReleaseId
        "categories" = New-Object System.Collections.ArrayList
    }
    $data
}

function Add-CfgMaxCategorySpecItem {
    param (
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [object[]]$Category,
        [object]$spec
    )

    foreach ($item in $category) {
        
        foreach ($subcategory in $item.subcategories) {
            $data = @{
                "categoryId"    = $item.id;
                "subCategoryId" = $subcategory.id
            }
            $spec.categories.add($data)
        }
    }
    $spec
}

function New-CfgMaxProductItem {
    param (
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        $Item
    )
    [PSCustomobject]@{
        "Id"          = $item.id;
        "Name"        = $item.rmVmwProduct;
        "ProductId"   = $item.rmVmwProductId;
        "PublishDate" = ConvertFrom-UnixTime -Timestamp $item.cmPublishDate;
        "Description" = $item.description;
    }
}

function New-CfgMaxReleaseItem {
    param (
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        $Item
    )
    [PSCustomobject]@{
        "Id"          = $item.id;
        "Version"     = $item.rmVmwPrdRelVersion;
        "ProductId"   = $item.cmVmwProductId;
        "ReleaseId"   = $item.rmVmwPrdRelId;
        "GADate"      = ConvertFrom-UnixTime -Timestamp $item.rmVmwPrdRelGADate;
        "PublishDate" = ConvertFrom-UnixTime -Timestamp $item.cmRelPublishDate;
        "LastUpdate"  = ConvertFrom-UnixTime -Timestamp $item.lastUpdate;
    }
}

function New-CfgMaxCategoryItem {
    param (
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        $Item
    )

    $categoryObject = [PSCustomobject]@{
        "Id"            = $item.id;
        "Category"      = $item.category.trim();
        "Description"   = $item.description;
        "ProductId"     = $item.cmVmwProductId;
        "ReleaseId"     = $item.cmVmwProdRelId;
        "LastUpdate"    = ConvertFrom-UnixTime -Timestamp $item.lastUpdate;
        "Child"         = $item.child;
        "subcategories" = New-Object System.Collections.ArrayList
    }

    foreach ($subcategoryItem in $item.subcategories) {
        $subCategoryObject = New-CfgMaxSubCategoryItem -Item $subcategoryItem
        $categoryObject.subcategories.Add($subCategoryObject) | Out-Null
    }

    $categoryObject
}

function New-CfgMaxSubCategoryItem {
    param (
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        $Item
    )

    [PSCustomobject]@{
        "Id"          = $item.id;
        "subCategory" = $item.subCategory.trim();
        "Description" = $item.decription;
        "LastUpdate"  = ConvertFrom-UnixTime -Timestamp $item.lastUpdate;
    }
}

function Invoke-CfgMaxParseLimitResponse {
    param (
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        $Limit
    )

    foreach ($category in $Limit) {
        foreach ($attribute in $category.configs) {
            $limitObject = [PSCustomobject]@{
                "Category"    = $category.name;
                "Group"       = $attribute.headername;
                "Limit"       = $attribute.keyName;
                "Value"       = $attribute.attrValue;
                "Description" = $attribute.description;
            }
            $limitObject
        }
    }
}

function Get-CfgMaxCompareIndexMap {
    <#
    .SYNOPSIS
    This cmdlet generates a mapping table of releases in order of the
    release/version rather than the GA date which is what is returned from the
    VMware Configuration Maximums site when doing a comparison of releases.

    .DESCRIPTION
    When multiple releases are submitted to the compare API, the order of the
    releases that are sent back in the response is based on the GA Date of the
    release. Unfortunatley, this means that there is a situation whereby an
    earlier realease (e.g. NSX-T Data Center 2.5.2) will be ordered AFTER a
    later release (e.g. NSX-T Data Center 3.0.0). Whilst this doesn't cause an
    issue when just displaying the output, because i've written some logic to
    show new/modified/deleted limits between the earliest and latest releases in
    the retruned comparison response, the order in which the results are
    returned actually matters.

    So this cmdlet, queries the releases for the product, as they are displayed
    in the correct order, and uses that ordered list of releases from the API,
    to generate a curated ordered hashtable of releases returned in the
    comparison response. The values assigned in the ordered hashtable are the
    index values of the release in the coparison response, so that the correct
    values for the releases can be looked up and displayed in the correct order.
    #>

    param (
        [Parameter (Mandatory = $true, ValueFromPipeline = $true)]
        [ValidateNotNullorEmpty()]
        $Product,
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        $ComparedReleases
    )

    $releases = $Product | Get-CfgMaxRelease | Sort-Object -Property Version | Select-Object Version
    $orderedReleases = [ordered]@{}
    foreach ($version in $($releases.version)) {
        if ($ComparedReleases -contains $version) {
            $orderedReleases[$version] = [array]::indexof($ComparedReleases, $version)
        }
    }
    Write-Verbose "Get-CfgMaxCompareIndexMap(): $($orderedReleases | ConvertTo-Json -Depth 100)"
    $orderedReleases
}

################################################################################
# Functions to export
################################################################################

function Get-CfgMaxProduct {
    <#
    .SYNOPSIS
    This cmdlet was designed to retrieve the list of products available on the
    VMware Configuration Maximums site.

    .DESCRIPTION
    Using a REST API call, this cmdlet will retrieve the complete list of
    products available on the VMware Configuration Maximums site. Each product
    that is discovered is returned as an individual object. Specifying no
    parameters will return all products. Alternativley, individual products can
    be returned by either specifying the -Id or -Name parameters.

    .PARAMETER Name
    Defines the product to return that is an exact name match.

    .PARAMETER Id
    Defines the product to return that is an exact Id match.

    .EXAMPLE
    Get-CfgMaxProduct

    Retrieves all products

    .EXAMPLE
    Get-CfgMaxProduct | Format-Table

    Retrieves all products and displays them all in a nice fancy table.

    .EXAMPLE
    Get-CfgMaxProduct -Name 'NSX Data Center for vSphere'
    
    Retrieves a product matching the exact name provided.

    .EXAMPLE
    Get-CfgMaxProduct -id 4
    
    Retrieves a product matching the Id provided.

    .NOTES
    Author(s): Dale Coghlan
    Twitter: @DaleCoghlan
    Github: dcoghlan

    .LINK
    https://github.com/dcoghlan/VMware.CfgMax
    #>


    [CmdLetBinding(DefaultParameterSetName = "Default")]
    
    param (
        [Parameter (Mandatory = $True, ParameterSetName = "Name")]
        [ValidateNotNullorEmpty()]
        [string]$Name,
        [Parameter (Mandatory = $True, ParameterSetName = "Id")]
        [int]$Id
    )

    $baseUri = New-Object System.UriBuilder($Script:urlBase)
    $baseUri.path = "/limits/menutree/v1/vmwareproducts"
    $baseUri.Query = Add-UriQueryParam -QueryObject $baseUri.Query -QueryString "hasconfigmaxset=true"
    try {
        $response = Invoke-RestMethod -Uri $baseUri.Uri -Headers $Script:CfgMaxHeaders
    }
    catch {
        throw "Unable to retieve config max products."
    }

    if ($response) {
        Write-Debug ($response | ConvertTo-Json -Depth 100)
        if ($PSCmdlet.ParameterSetName -eq 'Id') {
            $item = $response | Where-Object { $_.id -eq $Id }
            if ($item) {
                New-CfgMaxProductItem -Item $item
            }
        }
        elseif ($PSBoundParameters.ContainsKey("Name")) {
            $item = $response | Where-Object { $_.rmVmwProduct -eq $Name.trim() }
            if ($item) {
                New-CfgMaxProductItem -Item $item
            }
        }
        else {
            $data = New-Object System.Collections.ArrayList
            foreach ($item in $response) {
                $tempObject = New-CfgMaxProductItem -Item $item
                $data.Add($tempObject) | Out-Null
            }
            $data
        }
    }
}

function Get-CfgMaxRelease {
    <#
    .SYNOPSIS
    Retrieve the list of releases/versions of a given product available on the
    VMware Configuration Maximums site.
    
    .DESCRIPTION
    Retrieve the list of releases/versions of a given product available on the
    VMware Configuration Maximums site.
    
    .PARAMETER Product
    Specifies the product object, as returned from the cmdlet Get-CfgMaxProduct.
    
    .PARAMETER Version
    When specified, is used to return the releas/eversion that is an exact string
    match. Cannot be specified together with -Id parameter.
    
    .PARAMETER Id
    When specified, is used to return the release/version that is an exact Id
    match. Cannot be specified together with -Version parameter.
    
    .EXAMPLE
    Get-CfgMaxProduct -Name 'NSX-T Data Center' | Get-CfgMaxRelease | Format-Table

    Retrieves all the releases for the 'NSX-T Data Center' Product, and displays
    them all in a nice table
    
    .EXAMPLE
    Get-CfgMaxProduct -Name 'NSX-T Data Center' | Get-CfgMaxRelease -Version 'NSX-T Data Center 3.1.0'

    Retrieves a release matching the exact version provided.

    .EXAMPLE
    Get-CfgMaxProduct -Name 'NSX-T Data Center' | Get-CfgMaxRelease -Id 88

    Retrieves a specific release matching the Id provided.

    .NOTES
    Author(s): Dale Coghlan
    Twitter: @DaleCoghlan
    Github: dcoghlan

    .LINK
    https://github.com/dcoghlan/VMware.CfgMax
    #>


    [CmdLetBinding(DefaultParameterSetName = "Default")]
    param (
        [Parameter (Mandatory = $True, ValueFromPipeline = $true)]
        [ValidateNotNullorEmpty()]
        [object]$Product,
        [Parameter (Mandatory = $True, ParameterSetName = "Version")]
        [ValidateNotNullorEmpty()]
        [string]$Version,
        [Parameter (Mandatory = $True, ParameterSetName = "Id")]
        [int]$Id
    )
    $baseUri = New-Object System.UriBuilder($Script:urlBase)
    $baseUri.path = "/limits/menutree/v1/vmwareproducts/$($product.id)/releases"
    $baseUri.Query = Add-UriQueryParam -QueryObject $baseUri.Query -QueryString "hasconfigmaxset=true", "ispublished=true"
    try {
        $response = Invoke-RestMethod -Uri $baseUri.Uri -Headers $Script:CfgMaxHeaders
    }
    catch {
        throw "Unable to retieve config max releases."
    }
    $data = New-Object System.Collections.ArrayList
    if ($response) {
        Write-Debug ($response | ConvertTo-Json -Depth 100)
        if ($PSCmdlet.ParameterSetName -eq 'Id') {
            $item = $response | Where-Object { $_.id -eq $Id }
            if ($item) {
                New-CfgMaxReleaseItem -Item $Item
            }
        }
        elseif ($PSBoundParameters.ContainsKey("Version")) {
            $item = $response | Where-Object { $_.rmVmwPrdRelVersion -eq $Version.trim() }
            if ($item) {
                New-CfgMaxReleaseItem -Item $Item
            }
        }
        else {
            foreach ($item in $response) {
                $tempObject = New-CfgMaxReleaseItem -Item $Item
                $data.Add($tempObject) | Out-Null
            }
            $data
        }
    }
}

function Get-CfgMaxCategory {
    <#
    .SYNOPSIS
    Retrieve the list of categories of a given product/release combination
    available on the VMware Configuration Maximums site.
    
    .DESCRIPTION
    Retrieve the list of categories of a given product/release combination
    available on the VMware Configuration Maximums site.
    
    .PARAMETER Release
    Specifies the release object to retieve the categories for.
    
    .PARAMETER Id
    When specified, is used to return the category that is an exact Id
    match. Cannot be specified together with -Category parameter.
    
    .PARAMETER Category
    When specified, is used to return the category that is an exact string
    match. Cannot be specified together with -Id parameter.
    
    .EXAMPLE
    Get-CfgMaxProduct -Name 'NSX-T Data Center' | Get-CfgMaxRelease -Version 'NSX-T Data Center 3.1.0' | Get-CfgMaxCategory | Format-Table

    Retrieves all the categories for the 'NSX-T Data Center 3.1.0' release of
    the 'NSX-T Data Center' Product, and displays them all in a nice table

    .EXAMPLE
    Get-CfgMaxProduct -Name 'NSX-T Data Center' | Get-CfgMaxRelease -Version 'NSX-T Data Center 3.1.0' | Get-CfgMaxCategory -Id 17

    Retrieves a category matching the exact version provided.

    .EXAMPLE
    Get-CfgMaxProduct -Name 'NSX-T Data Center' | Get-CfgMaxRelease -Version 'NSX-T Data Center 3.1.0' | Get-CfgMaxCategory -Category 'Layer 3 Networking'
    
    Retrieves a category matching the exact category provided.

    .NOTES
    Author(s): Dale Coghlan
    Twitter: @DaleCoghlan
    Github: dcoghlan

    .LINK
    https://github.com/dcoghlan/VMware.CfgMax
    #>


    [CmdLetBinding(DefaultParameterSetName = "Default")]
    param (
        [Parameter (Mandatory = $true, ValueFromPipeline = $true)]
        [ValidateNotNullorEmpty()]
        [object]$Release,
        [Parameter (Mandatory = $True, ParameterSetName = "Id")]
        [ValidateNotNullorEmpty()]
        [int]$Id,
        [Parameter (Mandatory = $True, ParameterSetName = "Category")]
        [ValidateNotNullorEmpty()]
        [string]$Category
    )
    $baseUri = New-Object System.UriBuilder($Script:urlBase)
    $baseUri.path = "/limits/menutree/v1/vmwareproducts/$($Release.ProductId)/releases/$($Release.Id)/categories"

    try {
        $response = Invoke-RestMethod -Uri $baseUri.Uri -Headers $Script:CfgMaxHeaders
    }
    catch {
        throw "Unable to retieve config max categories for ID: $($Release.Id)."
    }

    if ($response) {
        Write-Debug ($response | ConvertTo-Json -Depth 100)
        if ($PSCmdlet.ParameterSetName -eq 'Id') {
            $item = $response | Where-Object { $_.id -eq $Id }
            New-CfgMaxCategoryItem -Item $item
        }
        elseif ($PSCmdlet.ParameterSetName -eq 'Category') {
            $item = $response | Where-Object { $_.category.trim() -eq $Category.trim() }
            New-CfgMaxCategoryItem -Item $item
        }
        else {
            $data = New-Object System.Collections.ArrayList
            foreach ($item in $response) {
                $data.Add($(New-CfgMaxCategoryItem -Item $item)) | Out-Null
            }
            $data
        }
    }
}

function Get-CfgMaxLimits {
    <#
    .SYNOPSIS
    Retrieve the list of limits from the VMware Configuration Maximums site
    based on the Product, Release and Categories specified.
    
    .DESCRIPTION
    Retrieve the list of limits from the VMware Configuration Maximums site
    based on the Product, Release and Categories specified.
    
    .PARAMETER Product
    Specifies the Product object to retieve the limits for.
    
    .PARAMETER Release
    Specifies the Release object to retieve the limits for.

    .PARAMETER Category
    Specifies the Category object to retieve the limits for.
    
    .EXAMPLE
    $product = Get-CfgMaxProduct -Name 'NSX-T Data Center'
    PS > $release = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 3.1.0'
    PS > Get-CfgMaxLimits -product $product -Release $release

    Retrieve the limits for the entire NSX-T 3.1.0 release (All Categories)

    .EXAMPLE
    $product = Get-CfgMaxProduct -Name 'NSX-T Data Center'
    PS > $release = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 3.1.0'
    PS > $category = $release | Get-CfgMaxCategory -Category 'Load Balancing'
    PS > Get-CfgMaxLimits -product $product -Release $release -Category $category

    Retrieve the limits for the NSX-T 3.1.0 Load Balancing Category only
    
    .NOTES
    Author(s): Dale Coghlan
    Twitter: @DaleCoghlan
    Github: dcoghlan

    .LINK
    https://github.com/dcoghlan/VMware.CfgMax
    #>


    param (
        [Parameter (Mandatory = $true)]
        [ValidateScript( { $_ })]
        [object]$Product,
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [object]$Release,
        [Parameter (Mandatory = $False)]
        [ValidateScript( { $_ })]
        [object[]]$Category
    )

    # process {

    $baseUri = New-Object System.UriBuilder($Script:urlBase)
    $baseUri.path = "/limits/managelimits/v1/vmwareproducts/$($Product.Id)/releases/$($Release.Id)/categories/attributes"
    $baseUri.Query = Add-UriQueryParam -QueryObject $baseUri.Query -QueryString "showall=false", "isTotalCount=false"

    $body = New-CfgMaxCategorySpec -ProductId $Product.Id -ReleaseId $Release.Id
    if ($Category) {
        Add-CfgMaxCategorySpecItem -spec $body -Category $Category | Out-Null
    }
    Write-Verbose $($body | ConvertTo-Json -Depth 100)

    try {
        $response = Invoke-RestMethod -Method POST -Uri $baseUri.uri -Headers $Script:CfgMaxHeaders -Body $($body | ConvertTo-Json -Depth 100)
    }
    catch {
        throw "Unable to retieve config max limits."
    }

    if ($response) {
        Write-Debug ($response | ConvertTo-Json -Depth 100)
        Invoke-CfgMaxParseLimitResponse -Limit $response 
    }

    # }
}

function Compare-CfgMaxLimits {
    <#
    .SYNOPSIS
    Compares the configuration maximum limits between different product releases
    to help identify which limits have been added, changed, removed or remain
    the same.

    .DESCRIPTION
    Compares the configuration maximum limits between different product releases
    to help identify which limits have been added, changed, removed or remain
    the same. It doesn't matter which release is provided to the -Release or
    -CompareRelease parameters, as the comparison will always be between the
    oldest and newest releases provided.

    .PARAMETER Product
    Specifies the Product object to that will be used for the comparison.

    .PARAMETER Release
    Specifies the Release object that is used as the base comparison object.

    .PARAMETER CompareReleases
    Specifies one or more Release objects to use for the comparison.

    .PARAMETER Show
    Specifies which types of limits are displayed. Default is All

    All = Displays all limits from all releases specified in the comparison.

    New = Limits which exist in the latest release specified in the comparison,
    which did not exist in the earliest release specified in the comparison.

    Modified = Limits which are different between the earliest and latest
    releases specified in the comparison.

    Deleted = Limits which exist in the earliest release specified in the
    comparison, which do not exist in the latest release specified in the
    comparison.

    .EXAMPLE
    $product = Get-CfgMaxProduct -Name 'NSX-T Data Center'
    PS > $releaseA = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 3.0.0'
    PS > $releaseB = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 2.5.2'
    PS > Compare-CfgMaxLimits -Product $product -Release $releaseA -CompareRelease $releaseB

    Compare the limits between NSX-T Data Center releases 2.5.2 and 3.0.0

    .EXAMPLE
    $product = Get-CfgMaxProduct -Name 'NSX-T Data Center'
    PS > $releaseA = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 3.0.0'
    PS > $releaseB = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 2.5.2'
    PS > Compare-CfgMaxLimits -Product $product -Release $releaseA -CompareRelease $releaseB | Format-Table

    Compare the limits between NSX-T Data Center releases 2.5.2 and 3.0.0 and format the output in a nice table

    .EXAMPLE
    $product = Get-CfgMaxProduct -Name 'NSX-T Data Center'
    PS > $releaseA = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 3.0.0'
    PS > $releaseB = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 2.5.2'
    PS > Compare-CfgMaxLimits -Product $product -Release $releaseA -CompareRelease $releaseB -Show New | Format-Table

    Compare the limits between NSX-T Data Center releases 2.5.2 and 3.0.0 and only display the newly added entries in a nicely formatted table

    .EXAMPLE
    $product = Get-CfgMaxProduct -Name 'NSX-T Data Center'
    PS > $releaseA = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 3.0.0'
    PS > $releaseB = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 2.5.2'
    PS > Compare-CfgMaxLimits -Product $product -Release $releaseA -CompareRelease $releaseB -Show Modified | Format-Table

    Compare the limits between NSX-T Data Center releases 2.5.2 and 3.0.0 and only display the modified entries in a nicely formatted table

    .EXAMPLE
    $product = Get-CfgMaxProduct -Name 'NSX-T Data Center'
    PS > $releaseA = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 3.0.0'
    PS > $releaseB = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 2.5.2'
    PS > Compare-CfgMaxLimits -Product $product -Release $releaseA -CompareRelease $releaseB -Show Deleted | Format-Table

    Compare the limits between NSX-T Data Center releases 2.5.2 and 3.0.0 and only display the deleted entries in a nicely formatted table

    .EXAMPLE
    $product = Get-CfgMaxProduct -Name 'NSX-T Data Center'
    PS > $releaseA = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 3.0.0'
    PS > $releaseB = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 2.5.2'
    PS > $releaseC = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 2.5.1'
    PS > $releaseD = $product | Get-CfgMaxRelease -Version 'NSX-T Data Center 3.0.1'
    PS > Compare-CfgMaxLimits -Product $product -Release $releaseA -CompareRelease $releaseB, $ReleaseC, $ReleaseD -Show All | Format-Table

    Compare the limits between NSX-T Data Center releases 2.5.1, 2.5.2, 3.0.0, and 3.1.1 and display the entries in a nicely formatted table

    .NOTES
    Author(s): Dale Coghlan
    Twitter: @DaleCoghlan
    Github: dcoghlan

    .LINK
    https://github.com/dcoghlan/VMware.CfgMax
    #>

    param (
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [object]$Product,
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [object]$Release,
        [Parameter (Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [object]$CompareRelease,
        [Parameter (Mandatory = $False)]
        [ ValidateSet("New", "Modified", "Deleted", "All") ]
        [string]$Show = "All"
    )

    $baseUri = New-Object System.UriBuilder($Script:urlBase)
    $baseUri.path = "/limits/comparelimits/v1/vmwareproducts/$($Product.Id)/releases/$($Release.Id)/configmaxset/comparision"
    $body = @{
        "vmwareProductId" = $Product.Id;
        "releaseIds"      = New-Object System.Collections.ArrayList
    }
    foreach ($rel in $CompareRelease) {
        $body.item('releaseIds').Add($rel.Id) | Out-Null
    }

    Write-Verbose $($body | ConvertTo-Json -Depth 100)
    try {
        $response = Invoke-RestMethod -Method POST -Uri $baseUri.uri -Headers $Script:CfgMaxHeaders -Body $($body | ConvertTo-Json -Depth 100)
    }
    catch {
        throw "Unable to compare config max limits."
    }
    
    if ($response) {
        Write-Debug ($response | ConvertTo-Json -Depth 100)

        $releaseOrderIndexMap = Get-CfgMaxCompareIndexMap -Product $Product -ComparedReleases $response.releases
        Write-Verbose "$($releaseOrderIndexMap | ConvertTo-Json -Depth 100)"
        $valueStartIndex = $releaseOrderIndexMap[($releaseOrderIndexMap.keys | Select-Object -First 1)]
        Write-Verbose "StartIndex = $valueStartIndex"
        $valueEndIndex = $releaseOrderIndexMap[($releaseOrderIndexMap.keys | Select-Object -Last 1)]
        Write-Verbose "EndIndex = $valueEndIndex"

        foreach ($category in $response.Categories) {
            foreach ($attribute in $category.attributes) {
                $limitObject = [PSCustomobject]@{
                    "Category" = $category.categoryName;
                    "Group"    = $attribute.attributeHeader;
                    "Limit"    = $attribute.attributKey;
                }
                foreach ($returnedReleaseName in $releaseOrderIndexMap.keys) {
                    $xlatedIndex = $releaseOrderIndexMap[$returnedReleaseName]
                    $limitObject | Add-Member -MemberType NoteProperty -Name $returnedReleaseName -Value (Convert-CfgMaxRawLimit -raw $attribute.attributeValues[$xlatedIndex])
                }

                $limitObject | Add-Member -MemberType NoteProperty -Name 'CompareStatus' -Value $null
                
                $valueStart = $attribute.attributeValues[$valueStartIndex]
                $valueEnd = $attribute.attributeValues[$valueEndIndex]
                if ( ($valueStart -eq 'NA') -AND ($valueEnd -ne 'NA') ) {
                    $limitObject.CompareStatus = 'New'
                }
                elseif ( ($valueEnd -eq 'NA') -AND ($valueStart -ne 'NA') ) {
                    $limitObject.CompareStatus = 'Deleted'
                }
                elseif ($valueStart -ne $valueEnd) {
                    $limitObject.CompareStatus = 'Modified'
                }
    
                switch ($Show) {
                    "New" {
                        if ($limitObject.CompareStatus -eq 'New') { $limitObject }
                        Break
                    }
                    "Modified" {
                        if ($limitObject.CompareStatus -eq 'Modified') { $limitObject }
                        Break
                    }
                    "Deleted" {
                        if ($limitObject.CompareStatus -eq 'Deleted') { $limitObject }
                        Break
                    }
                    Default {
                        $limitObject
                    }
                }
            }
        }
    }
}