From 24556bbe195a7fec85b124b3387d5cd67fbbaf9a Mon Sep 17 00:00:00 2001 From: William Lam Date: Thu, 10 Jan 2019 15:48:43 -0800 Subject: [PATCH 1/7] Fixed CSP Auth due to API change + Refresh Token expiry info --- Modules/VMware.CSP/VMware.CSP.psm1 | 44 ++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/Modules/VMware.CSP/VMware.CSP.psm1 b/Modules/VMware.CSP/VMware.CSP.psm1 index b4b4515..0562950 100644 --- a/Modules/VMware.CSP/VMware.CSP.psm1 +++ b/Modules/VMware.CSP/VMware.CSP.psm1 @@ -21,7 +21,8 @@ [Parameter(Mandatory=$true)][String]$RefreshToken ) - $results = Invoke-WebRequest -Uri "https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize?refresh_token=$RefreshToken" -Method POST -ContentType "application/json" -UseBasicParsing -Headers @{"csp-auth-token"="$RefreshToken"} + $body = "refresh_token=$RefreshToken" + $results = Invoke-WebRequest -Uri "https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize" -Method POST -ContentType "application/x-www-form-urlencoded" -UseBasicParsing -Body $body if($results.StatusCode -ne 200) { Write-Host -ForegroundColor Red "Failed to retrieve Access Token, please ensure your VMC Refresh Token is valid and try again" break @@ -51,4 +52,43 @@ Function Get-CSPServices { $results = Invoke-WebRequest -Uri "https://console.cloud.vmware.com/csp/gateway/slc/api/definitions?expand=1" -Method GET -ContentType "application/json" -UseBasicParsing -Headers @{"csp-auth-token"="$env:cspAuthToken"} ((($results.Content) | ConvertFrom-Json).results | where {$_.visible -eq $true}).displayName } -} \ No newline at end of file +} + +Function Get-CSPRefreshTokenExpiry { + <# + .NOTES + =========================================================================== + Created by: William Lam + Date: 01/10/2019 + Organization: VMware + Blog: https://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .DESCRIPTION + Retrieve the expiry for a given CSP Refresh Token + .PARAMETER RefreshToken + Retrieve the expiry for a given CSP Refresh Token + .EXAMPLE + Get-CSPRefreshTokenExpiry -RefreshToken $RefreshToken + #> + Param ( + [Parameter(Mandatory=$true)][String]$RefreshToken + ) + + $body = @{"tokenValue"="$RefreshToken"} + $json = $body | ConvertTo-Json + $results = Invoke-WebRequest -Uri "https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/details" -Method POST -ContentType "application/json" -UseBasicParsing -Body $json + $tokenDetails = (($results.Content) | ConvertFrom-Json) + + $createDate = (Get-Date -Date "01/01/1970").AddMilliseconds($tokenDetails.createdAt).ToLocalTime() + $usedDate = (Get-Date -Date "01/01/1970").AddMilliseconds($tokenDetails.lastUsedAt).ToLocalTime() + $expiryDate = (Get-Date -Date "01/01/1970").AddMilliseconds($tokenDetails.expiresAt).ToLocalTime() + + $tmp = [pscustomobject] @{ + LastUsedDate = $usedDate; + CreatedDate = $createDate; + ExpiryDate = $expiryDate; + } + $tmp | Format-List +} From 59ab2785e3b2d466672d48f7ae41c53df18d4886 Mon Sep 17 00:00:00 2001 From: William Lam Date: Sat, 12 Jan 2019 15:56:50 -0800 Subject: [PATCH 2/7] Added Set-VMCSDDC function to rename SDDC --- Modules/VMware.VMC/VMware.VMC.psm1 | 117 +++++++++++++++++++---------- 1 file changed, 77 insertions(+), 40 deletions(-) diff --git a/Modules/VMware.VMC/VMware.VMC.psm1 b/Modules/VMware.VMC/VMware.VMC.psm1 index 6605a14..b6c8541 100644 --- a/Modules/VMware.VMC/VMware.VMC.psm1 +++ b/Modules/VMware.VMC/VMware.VMC.psm1 @@ -918,23 +918,23 @@ Function Get-VMCPublicIP { .EXAMPLE Get-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName #> - Param ( - [Parameter(Mandatory=$True)]$OrgName, - [Parameter(Mandatory=$True)]$SDDCName - ) + Param ( + [Parameter(Mandatory=$True)]$OrgName, + [Parameter(Mandatory=$True)]$SDDCName + ) - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" - $publicIPs = $publicIPService.list($orgId,$sddcId) + $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" + $publicIPs = $publicIPService.list($orgId,$sddcId) - $publicIPs | select public_ip, name, allocation_id - } + $publicIPs | select public_ip, name, allocation_id } +} - Function New-VMCPublicIP { +Function New-VMCPublicIP { <# .NOTES =========================================================================== @@ -952,28 +952,28 @@ Function Get-VMCPublicIP { .EXAMPLE New-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -Description "Test for Randy" #> - Param ( - [Parameter(Mandatory=$True)]$OrgName, - [Parameter(Mandatory=$True)]$SDDCName, - [Parameter(Mandatory=$False)]$Description - ) + Param ( + [Parameter(Mandatory=$True)]$OrgName, + [Parameter(Mandatory=$True)]$SDDCName, + [Parameter(Mandatory=$False)]$Description + ) - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" + $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" - $publicIPSpec = $publicIPService.Help.create.spec.Create() - $publicIPSpec.count = 1 - $publicIPSpec.names = @($Description) + $publicIPSpec = $publicIPService.Help.create.spec.Create() + $publicIPSpec.count = 1 + $publicIPSpec.names = @($Description) - Write-Host "Requesting a new public IP Address for your SDDC ..." - $results = $publicIPService.create($orgId,$sddcId,$publicIPSpec) - } + Write-Host "Requesting a new public IP Address for your SDDC ..." + $results = $publicIPService.create($orgId,$sddcId,$publicIPSpec) } +} - Function Remove-VMCPublicIP { +Function Remove-VMCPublicIP { <# .NOTES =========================================================================== @@ -991,21 +991,58 @@ Function Get-VMCPublicIP { .EXAMPLE Remove-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -AllocationId "eipalloc-0567acf34e436c01f" #> - Param ( - [Parameter(Mandatory=$True)]$OrgName, - [Parameter(Mandatory=$True)]$SDDCName, - [Parameter(Mandatory=$True)]$AllocationId - ) + Param ( + [Parameter(Mandatory=$True)]$OrgName, + [Parameter(Mandatory=$True)]$SDDCName, + [Parameter(Mandatory=$True)]$AllocationId + ) - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" + $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" - Write-Host "Deleting public IP Address with ID $AllocationId ..." - $results = $publicIPService.delete($orgId,$sddcId,$AllocationId) + Write-Host "Deleting public IP Address with ID $AllocationId ..." + $results = $publicIPService.delete($orgId,$sddcId,$AllocationId) + } +} + +Function Set-VMCSDDC { + <# + .NOTES + =========================================================================== + Created by: William Lam + Date: 01/12/2019 + Organization: VMware + Blog: http://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Rename an SDDC + .DESCRIPTION + This cmdlet renames an SDDC + .EXAMPLE + Set-VMCSDDC -SDDC $SDDCName -OrgName $OrgName -Name $NewSDDCName + #> + Param ( + [Parameter(Mandatory=$True)]$SDDCName, + [Parameter(Mandatory=$True)]$OrgName, + [Parameter(Mandatory=$True)]$Name + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + $sddc = Get-VMCSDDC -Org $OrgName -Name $SDDCName + if($sddc) { + $sddcService = Get-VmcService com.vmware.vmc.orgs.sddcs + $renameSpec = $sddcService.help.patch.sddc_patch_request.Create() + $renameSpec.name = $Name + + Write-Host "`nRenaming SDDC `'$SDDCName`' to `'$Name`' ...`n" + $results = $sddcService.patch($sddc.org_id,$sddc.id,$renameSpec) } } +} -Export-ModuleMember -Function 'Get-VMCCommand', 'Connect-VMCVIServer', 'Get-VMCOrg', 'Get-VMCSDDC', 'Get-VMCTask', 'Get-VMCSDDCDefaultCredential', 'Get-VMCSDDCPublicIP', 'Get-VMCVMHost', 'Get-VMCSDDCVersion', 'Get-VMCFirewallRule', 'Export-VMCFirewallRule', 'Import-VMCFirewallRule', 'Remove-VMCFirewallRule', 'Get-VMCLogicalNetwork', 'Remove-VMCLogicalNetwork', 'New-VMCLogicalNetwork', 'Get-VMCSDDCSummary', 'Get-VMCPublicIP', 'New-VMCPublicIP', 'Remove-VMCPublicIP' +Export-ModuleMember -Function 'Get-VMCCommand', 'Connect-VMCVIServer', 'Get-VMCOrg', 'Get-VMCSDDC', 'Get-VMCTask', 'Get-VMCSDDCDefaultCredential', 'Get-VMCSDDCPublicIP', 'Get-VMCVMHost', 'Get-VMCSDDCVersion', 'Get-VMCFirewallRule', 'Export-VMCFirewallRule', 'Import-VMCFirewallRule', 'Remove-VMCFirewallRule', 'Get-VMCLogicalNetwork', 'Remove-VMCLogicalNetwork', 'New-VMCLogicalNetwork', 'Get-VMCSDDCSummary', 'Get-VMCPublicIP', 'New-VMCPublicIP', 'Remove-VMCPublicIP', 'Set-VMCSDDC' From ff3d297e697e943611b7fe4845c47f810b5dbcee Mon Sep 17 00:00:00 2001 From: William Lam Date: Thu, 17 Jan 2019 08:07:15 -0800 Subject: [PATCH 3/7] Fixing typo for creating NSX-T GW Firewall --- Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 b/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 index 72bc1e3..5466e41 100644 --- a/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 +++ b/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 @@ -476,7 +476,7 @@ Function New-NSXTFirewall { $services = @() foreach ($serviceName in $Service) { - if($group -eq "ANY") { + if($serviceName -eq "ANY") { $services = @("ANY") } else { $tmp = "/infra/services/$serviceName" From 216ee7386fecda5cfa1589c599739cdf7f75a7ba Mon Sep 17 00:00:00 2001 From: William Lam Date: Wed, 23 Jan 2019 05:25:14 -0800 Subject: [PATCH 4/7] Module for managing vCenter CEIP Settings --- Modules/vCenterCEIP/vCenterCEIP.psm1 | 74 ++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 Modules/vCenterCEIP/vCenterCEIP.psm1 diff --git a/Modules/vCenterCEIP/vCenterCEIP.psm1 b/Modules/vCenterCEIP/vCenterCEIP.psm1 new file mode 100755 index 0000000..3d5e903 --- /dev/null +++ b/Modules/vCenterCEIP/vCenterCEIP.psm1 @@ -0,0 +1,74 @@ +Function Get-VCenterCEIP { + <# + .NOTES + =========================================================================== + Created by: William Lam + Date: 01/23/2019 + Organization: VMware + Blog: http://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Retrieves the the Customer Experience Improvement Program (CEIP) setting for vCenter Server + .DESCRIPTION + This cmdlet retrieves the the CEIP setting for vCenter Server + .EXAMPLE + Get-VCenterCEIP + #> + If (-Not $global:DefaultVIServer.IsConnected) { Write-error "No valid VC Connection found, please use the Connect-VIServer to connect"; break } Else { + $ceipSettings = (Get-AdvancedSetting -Entity $global:DefaultVIServer -Name VirtualCenter.DataCollector.ConsentData).Value.toString() | ConvertFrom-Json + $ceipEnabled = $ceipSettings.consentConfigurations[0].consentAccepted + + $tmp = [pscustomobject] @{ + VCENTER = $global:DefaultVIServer.Name; + CEIP = $ceipEnabled; + } + $tmp + } +} +Function Set-VCenterCEIP { + <# + .NOTES + =========================================================================== + Created by: William Lam + Date: 01/23/2019 + Organization: VMware + Blog: http://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Enables or Disables the Customer Experience Improvement Program (CEIP) setting for vCenter Server + .DESCRIPTION + This cmdlet enables or disables the CEIP setting for vCenter Server + .EXAMPLE + Set-VCenterCEIP -Enabled + .EXAMPLE + Set-VCenterCEIP -Disabled + #> + Param ( + [Switch]$Enabled, + [Switch]$Disabled + ) + If (-Not $global:DefaultVIServer.IsConnected) { Write-error "No valid VC Connection found, please use the Connect-VIServer to connect"; break } Else { + $ceipSettings = (Get-AdvancedSetting -Entity $global:DefaultVIServer -Name VirtualCenter.DataCollector.ConsentData).Value.toString() | ConvertFrom-Json + If($Enabled) { + $originalVersion = $ceipSettings.version + $ceipSettings.version = [int]$originalVersion + 1 + $ceipSettings.consentConfigurations[0].consentAccepted = $True + $ceipSettings.consentConfigurations[1].consentAccepted = $True + $updatedceipSettings = $ceipSettings | ConvertTo-Json + Write-Host "Enabling Customer Experience Improvement Program (CEIP) ..." + Get-AdvancedSetting -Entity $global:DefaultVIServer -Name VirtualCenter.DataCollector.ConsentData | Set-AdvancedSetting -Value $updatedceipSettings -Confirm:$false + } else { + $originalVersion = $ceipSettings.version + $ceipSettings.version = [int]$originalVersion + 1 + $ceipSettings.consentConfigurations[0].consentAccepted = $False + $ceipSettings.consentConfigurations[1].consentAccepted = $False + $updatedceipSettings = $ceipSettings | ConvertTo-Json + Write-Host "Disablng Customer Experience Improvement Program (CEIP) ..." + Get-AdvancedSetting -Entity $global:DefaultVIServer -Name VirtualCenter.DataCollector.ConsentData | Set-AdvancedSetting -Value $updatedceipSettings -Confirm:$false + } + } +} From 6cc6634628e5e5c53c7e0c36eea46d410d584910 Mon Sep 17 00:00:00 2001 From: Kyle Ruddy Date: Fri, 1 Feb 2019 14:19:32 -0500 Subject: [PATCH 5/7] Create Set-NetworkAdapterOpaqueNetwork.ps1 Code sample provided as part of KB 65149: https://kb.vmware.com/s/article/65149 --- Scripts/Set-NetworkAdapterOpaqueNetwork.ps1 | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Scripts/Set-NetworkAdapterOpaqueNetwork.ps1 diff --git a/Scripts/Set-NetworkAdapterOpaqueNetwork.ps1 b/Scripts/Set-NetworkAdapterOpaqueNetwork.ps1 new file mode 100644 index 0000000..1310734 --- /dev/null +++ b/Scripts/Set-NetworkAdapterOpaqueNetwork.ps1 @@ -0,0 +1,50 @@ +function Set-NetworkAdapterOpaqueNetwork { +param( + [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 1)] + [VMware.VimAutomation.Types.NetworkAdapter] + $NetworkAdapter, + + [Parameter(Mandatory = $true, Position = 2)] + [string] + $OpaqueNetworkName, + + [Parameter()] + [switch] + $Connected, + + [Parameter()] + [switch] + $StartConnected +) +process { + $opaqueNetwork = Get-View -ViewType OpaqueNetwork | ? {$_.Name -eq $OpaqueNetworkName} + if (-not $opaqueNetwork) { + throw "'$OpaqueNetworkName' network not found." + } + + $opaqueNetworkBacking = New-Object VMware.Vim.VirtualEthernetCardOpaqueNetworkBackingInfo + $opaqueNetworkBacking.OpaqueNetworkId = $opaqueNetwork.Summary.OpaqueNetworkId + $opaqueNetworkBacking.OpaqueNetworkType = $opaqueNetwork.Summary.OpaqueNetworkType + + $device = $NetworkAdapter.ExtensionData + $device.Backing = $opaqueNetworkBacking + + if ($StartConnected) { + $device.Connectable.StartConnected = $true + } + + if ($Connected) { + $device.Connectable.Connected = $true + } + + $spec = New-Object VMware.Vim.VirtualDeviceConfigSpec + $spec.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::edit + $spec.Device = $device + $configSpec = New-Object VMware.Vim.VirtualMachineConfigSpec + $configSpec.DeviceChange = @($spec) + $NetworkAdapter.Parent.ExtensionData.ReconfigVM($configSpec) + + # Output + Get-NetworkAdapter -Id $NetworkAdapter.Id + } +} From 407be173e404bf388e93698a8695206bc7b8e06c Mon Sep 17 00:00:00 2001 From: William Lam Date: Sat, 2 Feb 2019 07:34:16 -0800 Subject: [PATCH 6/7] Adding NSX-T Routing Table --- Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 | 79 ++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 b/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 index 5466e41..bc2cebd 100644 --- a/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 +++ b/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 @@ -1361,4 +1361,83 @@ Function Remove-NSXTDistFirewall { Write-Host "Succesfully removed NSX-T Distributed Firewall Rule" } } +} + +Function Get-NSXTRouteTable { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: 02/02/2019 + Organization: VMware + Blog: http://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Retrieves NSX-T Routing Table + .DESCRIPTION + This cmdlet retrieves NSX-T Routing Table. By default, it shows all routes but you can filter by BGP, CONNECTED or STATIC routes + .EXAMPLE + Get-NSXTRouteTable + .EXAMPLE + Get-NSXTRouteTable -RouteSource BGP + .EXAMPLE + Get-NSXTRouteTable -RouteSource CONNECTED + .EXAMPLE + Get-NSXTRouteTable -RouteSource STATIC + .EXAMPLE + Get-NSXTRouteTable -RouteSource BGP -Troubleshoot +#> + Param ( + [Parameter(Mandatory=$False)][ValidateSet("BGP","CONNECTED","STATIC")]$RouteSource, + [Switch]$Troubleshoot + ) + + If (-Not $global:nsxtProxyConnection) { Write-error "No NSX-T Proxy Connection found, please use Connect-NSXTProxy" } Else { + $method = "GET" + $routeTableURL = $global:nsxtProxyConnection.Server + "/policy/api/v1/infra/tier-0s/vmc/routing-table?enforcement_point_path=/infra/deployment-zones/default/enforcement-points/vmc-enforcementpoint" + + if($RouteSource) { + $routeTableURL = $routeTableURL + "&route_source=$RouteSource" + } + + if($Troubleshoot) { + Write-Host -ForegroundColor cyan "`n[DEBUG] - $method`n$routeTableURL`n" + } + + try { + if($PSVersionTable.PSEdition -eq "Core") { + $requests = Invoke-WebRequest -Uri $routeTableURL -Method $method -Headers $global:nsxtProxyConnection.headers -SkipCertificateCheck + } else { + $requests = Invoke-WebRequest -Uri $routeTableURL -Method $method -Headers $global:nsxtProxyConnection.headers + } + } catch { + if($_.Exception.Response.StatusCode -eq "Unauthorized") { + Write-Host -ForegroundColor Red "`nThe NSX-T Proxy session is no longer valid, please re-run the Connect-NSXTProxy cmdlet to retrieve a new token`n" + break + } else { + Write-Error "Error in retrieving NSX-T Routing Table" + Write-Error "`n($_.Exception.Message)`n" + break + } + } + + if($requests.StatusCode -eq 200) { + Write-Host "Succesfully retrieved NSX-T Routing Table`n" + $routeTables = ($requests.Content | ConvertFrom-Json).results + + foreach ($routeTable in $routeTables) { + Write-Host "EdgeNode: $($routeTable.edge_node)" + Write-Host "Entries: $($routeTable.count)" + + $routeEntries = $routeTable.route_entries + $routeEntryResults = @() + foreach ($routeEntry in $routeEntries) { + $routeEntryResults += $routeEntry + } + $routeEntryResults | select network,next_hop,admin_distance,route_type | ft + } + } + } } \ No newline at end of file From 2212477dff9ca34a0e16d34dcd792ad6978993d8 Mon Sep 17 00:00:00 2001 From: William Lam Date: Fri, 8 Feb 2019 05:28:10 -0800 Subject: [PATCH 7/7] Added NSX-T Overview Info --- Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psd1 | 2 +- Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 | 55 ++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psd1 b/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psd1 index ef45018..b74bad7 100644 --- a/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psd1 +++ b/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psd1 @@ -36,7 +36,7 @@ Description = 'PowerShell Module for Managing NSX-T on VMware Cloud on AWS' PowerShellVersion = '6.0' # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = 'Connect-NSXTProxy', 'Get-NSXTSegment', 'New-NSXTSegment', 'Remove-NSXTSegment', 'Get-NSXTGroup', 'New-NSXTGroup', 'Remove-NSXTGroup', 'Get-NSXTService', 'New-NSXTService', 'Get-NSXTFirewall', 'New-NSXTFirewall', 'Remove-NSXTFirewall', 'Get-NSXTDistFirewallSection', 'Get-NSXTDistFirewall', 'New-NSXTDistFirewall', 'Remove-NSXTDistFirewall' +FunctionsToExport = 'Connect-NSXTProxy', 'Get-NSXTSegment', 'New-NSXTSegment', 'Remove-NSXTSegment', 'Get-NSXTGroup', 'New-NSXTGroup', 'Remove-NSXTGroup', 'Get-NSXTService', 'New-NSXTService', 'Get-NSXTFirewall', 'New-NSXTFirewall', 'Remove-NSXTFirewall', 'Get-NSXTDistFirewallSection', 'Get-NSXTDistFirewall', 'New-NSXTDistFirewall', 'Remove-NSXTDistFirewall', 'Get-NSXTRouteTable', 'Get-NSXTOverviewInfo' # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @() diff --git a/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 b/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 index bc2cebd..d120086 100644 --- a/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 +++ b/Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1 @@ -1440,4 +1440,59 @@ Function Get-NSXTRouteTable { } } } +} + +Function Get-NSXTOverviewInfo { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: 02/02/2019 + Organization: VMware + Blog: http://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Retrieves NSX-T Overview including the VPN internet IP Address and SDDC Infra/Mgmt Subnets, etc. + .DESCRIPTION + This cmdlet retrieves NSX-T Overview details including the VPN internet IP Address and SDDC Infra/Mgmt Subnets, etc. + .EXAMPLE + Get-NSXTOverviewInfo +#> +Param ( + [Parameter(Mandatory=$False)][ValidateSet("BGP","CONNECTED","STATIC")]$RouteSource, + [Switch]$Troubleshoot +) + +If (-Not $global:nsxtProxyConnection) { Write-error "No NSX-T Proxy Connection found, please use Connect-NSXTProxy" } Else { + $method = "GET" + $overviewURL = $global:nsxtProxyConnection.Server + "/cloud-service/api/v1/infra/sddc-user-config" + + if($Troubleshoot) { + Write-Host -ForegroundColor cyan "`n[DEBUG] - $method`n$overviewURL`n" + } + + try { + if($PSVersionTable.PSEdition -eq "Core") { + $requests = Invoke-WebRequest -Uri $overviewURL -Method $method -Headers $global:nsxtProxyConnection.headers -SkipCertificateCheck + } else { + $requests = Invoke-WebRequest -Uri $overviewURL -Method $method -Headers $global:nsxtProxyConnection.headers + } + } catch { + if($_.Exception.Response.StatusCode -eq "Unauthorized") { + Write-Host -ForegroundColor Red "`nThe NSX-T Proxy session is no longer valid, please re-run the Connect-NSXTProxy cmdlet to retrieve a new token`n" + break + } else { + Write-Error "Error in retrieving NSX-T Overview Information" + Write-Error "`n($_.Exception.Message)`n" + break + } + } + + if($requests.StatusCode -eq 200) { + Write-Host "Succesfully retrieved NSX-T Overview Information" + ($requests.Content | ConvertFrom-Json) + } +} } \ No newline at end of file