#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE#SOFTWARE.

### Note#This powershell module should be considered entirely experimental. It is still#in development & not tested beyond lab scenarios.#It is recommended you dont use it for any production environment#without testing extensively!

# Enable communication with self signed certs when using Powershell Core# If you require all communications to be secure and do not wish to# allow communication with self signed certs remove lines 31-52 before# importing the module

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif(-not$PsBoundParameters.ContainsKey("regionType")-and(-not$PsBoundParameters.ContainsKey("id"))){$uri="https://$sddcManager/v1/avns"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}if($PsBoundParameters.ContainsKey("regionType")){$uri="https://$sddcManager/v1/avns?regionType=$regionType"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}if($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/internal/avns/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFApplicationVirtualNetwork

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/system/backup-configuration"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.backupLocations}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFBackupConfiguration

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary# this body is fixed for SDDC Manager backups. not worth having it stored on file$ConfigJson='{"elements" : [{"resourceType" : "SDDC_MANAGER"}]}'$uri="https://$sddcManager/v1/backups/tasks"$response=Invoke-RestMethod-MethodPOST-URI$uri-headers$headers-ContentType"application/json"-body$ConfigJson$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionStart-VCFBackup

Try{if($PsBoundParameters.ContainsKey("id")){createBasicAuthHeader$uri="https://$sddcManager/v1/restores/tasks/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFRestoreTask

######### End APIs for managing Backup and Restore ##########

######### Start APIs for managing Bundles ##########

FunctionGet-VCFBundle{<#
.SYNOPSIS
Get all Bundles available to SDDC Manager

.DESCRIPTION
The Get-VCFBundle cmdlet gets all bundles available to the SDDC Manager instance.
i.e. Manually uploaded bundles and bundles available via depot access.

.EXAMPLE
PS C:\> Get-VCFBundle
This example gets the list of bundles and all their details

.EXAMPLE
PS C:\> Get-VCFBundle | Select version,downloadStatus,id
This example gets the list of bundles and filters on the version, download status and the id only

.EXAMPLE
PS C:\> Get-VCFBundle -id 7ef354ab-13a6-4e39-9561-10d2c4de89db
This example gets the details of a specific bundle by its id

.EXAMPLE
PS C:\> Get-VCFBundle | Where {$_.description -Match "vRealize"}
This example lists all bundles that match vRealize in the description field
#>

Param([Parameter(Mandatory=$false)][string]$id)

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/bundles/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}else{$uri="https://$sddcManager/v1/bundles"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFBundle

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/bundles/$id"$body='{"bundleDownloadSpec": {"downloadNow": true}}'$response=Invoke-RestMethod-MethodPATCH-URI$uri-headers$headers-ContentTypeapplication/json-body$body$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionRequest-VCFBundle

FunctionGet-VCFCeip{<#
.SYNOPSIS
Retrieves the current setting for CEIP of the connected SDDC Manager

.DESCRIPTION
The Get-VCFCeip cmdlet retrieves the current setting for Customer Experience Improvement Program (CEIP) of the connected SDDC Manager

.EXAMPLE
PS C:\> Get-VCFCeip
This example shows how to get the current setting of CEIP
#>

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessarycheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/system/ceip"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFCeip

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/system/ceip"if(-not$PsBoundParameters.ContainsKey("ceipsetting")){Throw"You must define ENABLE or DISABLE as an input"}if($ceipSetting-eq"ENABLE"){$ConfigJson='{"status": "ENABLE"}'}if($ceipSetting-eq"DISABLE"){$ConfigJson='{"status": "DISABLE"}'}$response=Invoke-RestMethod-MethodPATCH-URI$uri-ContentTypeapplication/json-headers$headers-body$ConfigJson$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionSet-VCFCeip

.EXAMPLE
PS C:\> Get-VCFCertificateAuthority
This example shows how to get the certificate authority configuration from the connected SDDC Manager

.EXAMPLE
PS C:\> Get-VCFCertificateAuthority | ConvertTo-Json
This example shows how to get the certificate authority configuration from the connected SDDC Manager
and output to Json format

.EXAMPLE
PS C:\> Get-VCFCertificateAuthority -caType Microsoft
This example shows how to get the certificate authority configuration for a Microsoft Certificate Authority from the
connected SDDC Manager
#>

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif($PsBoundParameters.ContainsKey("caType")){$uri="https://$sddcManager/v1/certificate-authorities/$caType"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}else{$uri="https://$sddcManager/v1/certificate-authorities"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFCertificateAuthority

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/certificate-authorities/$caType"$response=Invoke-RestMethod-MethodDELETE-URI$uri-headers$headers$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionRemove-VCFCertificateAuthority

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/certificate-authorities"if(-not$PsBoundParameters.ContainsKey("serverUrl")-and(-not$PsBoundParameters.ContainsKey("username")-and(-not$PsBoundParameters.ContainsKey("password")-and(-not$PsBoundParameters.ContainsKey("templateName"))))){Throw"You must enter the mandatory values"}$ConfigJson='{"microsoftCertificateAuthoritySpec": {"secret": "'+$password+'","serverUrl": "'+$serverUrl+'","username": "'+$username+'","templateName": "'+$templateName+'"}}'Invoke-RestMethod-MethodPUT-URI$uri-ContentTypeapplication/json-headers$headers-body$ConfigJson# No response from API}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionSet-VCFMicrosoftCA

FunctionGet-VCFCertificateCSR{<#
.SYNOPSIS
Get available CSR(s)

.DESCRIPTION
The Get-VCFCertificateCSR cmdlet gets the available CSRs that have been created on SDDC Manager

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/domains/$domainName/csrs"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFCertificateCSR

.EXAMPLE
PS C:\> Request-VCFCertificateCSR -domainName MGMT -json .\requestCsrSpec.json
This example requests the generation of the CSR based on the entries within the requestCsrSpec.json file for resources within
the domain called MGMT
#>

if(!(Test-Path$json)){Throw"JSON File Not Found"}else{$ConfigJson=(Get-Content-Raw$json)# Reads the requestCsrSpec json file contents into the $ConfigJson variablecreateHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/domains/$domainName/csrs"Try{$response=Invoke-RestMethod-MethodPUT-URI$uri-headers$headers-ContentTypeapplication/json-body$ConfigJson$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}}Export-ModuleMember-FunctionRequest-VCFCertificateCSR

FunctionGet-VCFCertificate{<#
.SYNOPSIS
Get latest generated certificate(s) in a domain

.DESCRIPTION
The Get-VCFCertificate cmdlet gets the latest generated certificate(s) in a domain

.EXAMPLE
PS C:\> Get-VCFCertificate -domainName sfo-m01
This example gets a list of certificates that have been generated

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif($PsBoundParameters.ContainsKey("resources")){$uri="https://$sddcManager/v1/domains/$domainName/resource-certificates"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}else{$uri="https://$sddcManager/v1/domains/$domainName/certificates"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFCertificate

FunctionRequest-VCFCertificate{<#
.SYNOPSIS
Generate certificate(s) for the selected resource(s) in a domain

.EXAMPLE
PS C:\> Request-VCFCertificate -domainName MGMT -json .\requestCertificateSpec.json
This example requests the generation of the Certificates based on the entries within the requestCertificateSpec.json file
for resources within the domain called MGMT
#>

if(!(Test-Path$json)){Throw"JSON File Not Found"}else{# Reads the requestCsrSpec json file contents into the $ConfigJson variable$ConfigJson=(Get-Content-Raw$json)createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/domains/$domainName/certificates"Try{$response=Invoke-RestMethod-MethodPUT-URI$uri-headers$headers-ContentTypeapplication/json-body$ConfigJson$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}}Export-ModuleMember-FunctionRequest-VCFCertificate

FunctionSet-VCFCertificate{<#
.SYNOPSIS
Replace certificate(s) for the selected resource(s) in a domain

.DESCRIPTION
The Set-VCFCertificate cmdlet replaces certificate(s) for the selected resource(s) in a domain

.EXAMPLE
PS C:\> Set-VCFCertificate -domainName MGMT -json .\updateCertificateSpec.json
This example replaces the Certificates based on the entries within the requestCertificateSpec.json file
for resources within the domain called MGMT
#>

if(!(Test-Path$json)){Throw"JSON File Not Found"}else{$ConfigJson=(Get-Content-Raw$json)# Reads the updateCertificateSpec json file contents into the $ConfigJson variablecreateHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/domains/$domainName/certificates"Try{$response=Invoke-RestMethod-MethodPATCH-URI$uri-headers$headers-ContentTypeapplication/json-body$ConfigJson$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}}Export-ModuleMember-FunctionSet-VCFCertificate

createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryTry{if(-not$PsBoundParameters.ContainsKey("name")-and(-not$PsBoundParameters.ContainsKey("id"))){$uri="https://$sddcManager/v1/clusters"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/clusters/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}if($PsBoundParameters.ContainsKey("name")){$uri="https://$sddcManager/v1/clusters"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements|Where-Object{$_.name-eq$name}}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFCluster

FunctionNew-VCFCluster{<#
.SYNOPSIS
Connects to the specified SDDC Manager and creates a cluster

.DESCRIPTION
The New-VCFCluster cmdlet connects to the specified SDDC Manager and creates a cluster in a specified workload domains

.EXAMPLE
PS C:\> New-VCFCluster -json .\WorkloadDomain\addClusterSpec.json
This example shows how to create a cluster in a Workload Domain from a json spec
#>

if(!(Test-Path$json)){Throw"JSON File Not Found"}else{$ConfigJson=(Get-Content$json)# Read the json file contents into the $ConfigJson variablecreateHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary# Validate the provided JSON input specification file$response=Validate-VCFClusterSpec-json$ConfigJson# the validation API does not currently support polling with a task IDStart-Sleep5# Submit the job only if the JSON validation task finished with executionStatus=COMPLETED & resultStatus=SUCCEEDEDif($response.executionStatus-eq"COMPLETED"-and$response.resultStatus-eq"SUCCEEDED"){Try{Write-Host"`n Task validation completed successfully, invoking cluster task on SDDC Manager `n"-ForegroundColorGreen$uri="https://$sddcManager/v1/clusters"$response=Invoke-RestMethod-MethodPOST-URI$uri-ContentTypeapplication/json-headers$headers-body$ConfigJson$response.elements}Catch{ResponseException# Call ResponseException function to get error response from the exception}else{Write-Host"`n The validation task commpleted the run with the following problems: `n"-ForegroundColorYellowWrite-Host$response.validationChecks.errorResponse.message`n-ForegroundColorYellow}}}}Export-ModuleMember-FunctionNew-VCFCluster

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif(-not$PsBoundParameters.ContainsKey("json")-and(-not$PsBoundParameters.ContainsKey("markForDeletion"))){Throw"You must include either -json or -markForDeletion"}if($PsBoundParameters.ContainsKey("json")){validateJsonInput# Calls validateJsonInput Function to check the JSON file provided exists# Validate the provided JSON input specification file$response=Validate-VCFUpdateClusterSpec-clusterid$id-json$ConfigJson# the validation API does not currently support polling with a task IDStart-Sleep5# Submit the job only if the JSON validation task finished with executionStatus=COMPLETED & resultStatus=SUCCEEDEDif($response.executionStatus-eq"COMPLETED"-and$response.resultStatus-eq"SUCCEEDED"){Try{Write-Host"`n Task validation completed successfully, invoking cluster task on SDDC Manager `n"-ForegroundColorGreen$uri="https://$sddcManager/v1/clusters/$id/"$response=Invoke-RestMethod-MethodPATCH-URI$uri-headers$headers-ContentTypeapplication/json-body$ConfigJson$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}else{Write-Host"`n The validation task commpleted the run with the following problems: `n"-ForegroundColorYellowWrite-Host" "$response.validationChecks.errorResponse.message`n-ForegroundColorYellow}}if($PsBoundParameters.ContainsKey("markForDeletion")-and($PsBoundParameters.ContainsKey("id"))){$ConfigJson='{"markForDeletion": true}'$uri="https://$sddcManager/v1/clusters/$id/"$response=Invoke-RestMethod-MethodPATCH-URI$uri-ContentTypeapplication/json-headers$headers-body$ConfigJson}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionSet-VCFCluster

createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryTry{$uri="https://$sddcManager/v1/clusters/$id"$response=Invoke-RestMethod-MethodDELETE-URI$uri-headers$headers$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionRemove-VCFCluster

FunctionGet-VCFClusterValidation{<#
.SYNOPSIS
Get the status of the validations for cluster deployment

.DESCRIPTION
The Get-VCFClusterValidation cmdlet returns the status of a validation of the json

.EXAMPLE
PS C:\> Get-VCFClusterValidation -id 001235d8-3e40-4a5a-8a89-09985dac1434
This example shows how to get the cluster validation task based on the id
#>

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/clusters/validations/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFClusterValidation

######### End APIs for managing Clusters ##########

######### Start APIs for managing Credentials ##########

FunctionGet-VCFCredential{<#
.SYNOPSIS
Connects to the specified SDDC Manager and retrieves a list of credentials.
Supported resource types are: VCENTER, ESXI, NSXT_MANAGER, NSXT_EDGE, BACKUP
Please note: if you are requesting credentials by resource type then the resource name parameter (if
passed) will be ignored (they are mutually exclusive)

.DESCRIPTION
The Get-VCFCredential cmdlet connects to the specified SDDC Manager and retrieves a list of credentials.
Authenticated user must have ADMIN role.

.EXAMPLE
PS C:\> Get-VCFCredential
This example shows how to get a list of credentials

.EXAMPLE
PS C:\> Get-VCFCredential -resourceType VCENTER
This example shows how to get a list of VCENTER credentials

.EXAMPLE
PS C:\> Get-VCFCredential -resourceName sfo01-m01-esx01.sfo.rainpole.io
This example shows how to get the credential for a specific resourceName (FQDN)

.EXAMPLE
PS C:\> Get-VCFCredential -id 3c4acbd6-34e5-4281-ad19-a49cb7a5a275
This example shows how to get the credential using the id
#>

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif($PsBoundParameters.ContainsKey("resourceName")){$uri="https://$sddcManager/v1/credentials?resourceName=$resourceName"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}elseif($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/credentials/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}# if requesting credential by type then name is ignored (mutually exclusive)elseif($PsBoundParameters.ContainsKey("resourceType")){$uri="https://$sddcManager/v1/credentials?resourceType=$resourceType"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}else{$uri="https://$sddcManager/v1/credentials"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFCredential

FunctionSet-VCFCredential{<#
.SYNOPSIS
Connects to the specified SDDC Manager and updates a credential.

.DESCRIPTION
The Set-VCFCredential cmdlet connects to the specified SDDC Manager and updates a credential.
Credentials can be updated with a specified password(s) or rotated using system generated password(s).

.EXAMPLE
PS C:\> Set-VCFCredential -json .\Credential\updateCredentialSpec.json
This example shows how to update a credential using a json spec
#>

Try{if($PsBoundParameters.ContainsKey("json")){if(!(Test-Path$json)){Throw"JSON File Not Found"}else{$ConfigJson=(Get-Content$json)# Read the json file contents into the $ConfigJson variable}}createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/credentials"$response=Invoke-RestMethod-MethodPATCH-URI$uri-ContentTypeapplication/json-headers$headers-body$ConfigJson$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionSet-VCFCredential

FunctionGet-VCFCredentialTask{<#
.SYNOPSIS
Connects to the specified SDDC Manager and retrieves a list of credential tasks in reverse chronological order.

.DESCRIPTION
The Get-VCFCredentialTask cmdlet connects to the specified SDDC Manager and retrieves a list of
credential tasks in reverse chronological order.

.EXAMPLE
PS C:\> Get-VCFCredentialTask
This example shows how to get a list of all credentials tasks

.EXAMPLE
PS C:\> Get-VCFCredentialTask -id 7534d35d-98fb-43de-bcf7-2776beb6fcc3
This example shows how to get the credential tasks for a specific task id

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif(-not$PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/credentials/tasks"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/credentials/tasks/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}if($PsBoundParameters.ContainsKey("id")-and($PsBoundParameters.ContainsKey("resourceCredentials"))){$uri="https://$sddcManager/v1/credentials/tasks/$id/resource-credentials"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFCredentialTask

if($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/credentials/tasks/$id"}else{Throw"task id to be cancelled is not provided"}createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryTry{$response=Invoke-RestMethod-MethodDELETE-URI$uri-ContentTypeapplication/json-headers$headers$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionStop-VCFCredentialTask

if($PsBoundParameters.ContainsKey("json")){if(!(Test-Path$json)){Throw"JSON File Not Found"}else{$ConfigJson=(Get-Content$json)# Read the json file contents into the $ConfigJson variable}}if($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/credentials/tasks/$id"}else{Throw"task id not provided"}createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryTry{$response=Invoke-RestMethod-MethodPATCH-URI$uri-ContentTypeapplication/json-headers$headers-body$ConfigJson$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionRestart-VCFCredentialTask

######### End APIs for managing Credentials ##########

######### Start APIs for managing Depot Settings ##########

FunctionGet-VCFDepotCredential{<#
.SYNOPSIS
Get Depot Settings

.DESCRIPTION
Retrieves the configuration for the depot of the connected SDDC Manager

.EXAMPLE
PS C:\> Get-VCFDepotCredential
This example shows credentials that have been configured for the depot.
#>

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/system/settings/depot"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.vmwareAccount}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFDepotCredential

FunctionSet-VCFDepotCredential{<#
.SYNOPSIS
Update the Depot Settings

.DESCRIPTION
Update the configuration for the depot of the connected SDDC Manager

.EXAMPLE
PS C:\> Set-VCFDepotCredential -username "user@yourdomain.com" -password "VMware1!"
This example sets the credentials that have been configured for the depot.
#>

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/system/settings/depot"if(-not$PsBoundParameters.ContainsKey("username")-and(-not$PsBoundParameters.ContainsKey("password"))){Throw"You must enter a username and password"}$ConfigJson='{"vmwareAccount": {"username": "'+$username+'","password": "'+$password+'"}}'$response=Invoke-RestMethod-MethodPUT-URI$uri-ContentTypeapplication/json-headers$headers-body$ConfigJson$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionSet-VCFDepotCredential

.EXAMPLE
PS C:\> Get-VCFWorkloadDomain
This example shows how to get a list of Workload Domains

.EXAMPLE
PS C:\> Get-VCFWorkloadDomain -name WLD01
This example shows how to get a Workload Domain by name

.EXAMPLE
PS C:\> Get-VCFWorkloadDomain -id 8423f92e-e4b9-46e7-92f7-befce4755ba2
This example shows how to get a Workload Domain by id

.EXAMPLE
PS C:\> Get-VCFWorkloadDomain -id 8423f92e-e4b9-46e7-92f7-befce4755ba2 -endpoints | ConvertTo-Json
This example shows how to get endpoints of a Workload Domain by its id and displays the output in Json format
#>

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif($PsBoundParameters.ContainsKey("name")){$uri="https://$sddcManager/v1/domains"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements|Where-Object{$_.name-eq$name}}if($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/domains/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}if(-not$PsBoundParameters.ContainsKey("name")-and(-not$PsBoundParameters.ContainsKey("id"))){$uri="https://$sddcManager/v1/domains"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if($PsBoundParameters.ContainsKey("id")-and($PsBoundParameters.ContainsKey("endpoints"))){$uri="https://$sddcManager/v1/domains/$id/endpoints"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFWorkloadDomain

Try{validateJsonInput# Calls validateJsonInput Function to check the JSON file provided existscreateHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$response=Validate-WorkloadDomainSpec-json$ConfigJson# Validate the provided JSON input specification file # the validation API does not currently support polling with a task IDStart-Sleep5# Submit the job only if the JSON validation task completed with executionStatus=COMPLETED & resultStatus=SUCCEEDEDif($response.executionStatus-eq"COMPLETED"-and$response.resultStatus-eq"SUCCEEDED"){Write-Host"`n Task validation completed successfully, invoking Workload Domain Creation on SDDC Manager `n"-ForegroundColorGreen$uri="https://$sddcManager/v1/domains"$response=Invoke-RestMethod-MethodPOST-URI$uri-ContentTypeapplication/json-headers$headers-body$ConfigJsonReturn$response}else{Write-Host"`n The validation task commpleted the run with the following problems: `n"-ForegroundColorYellowWrite-Host$response.validationChecks.errorResponse.message`n-ForegroundColorYellow}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionNew-VCFWorkloadDomain

.DESCRIPTION
Before a workload domain can be deleted it must first be marked for deletion.
The Set-VCFWorkloadDomain cmdlet connects to the specified SDDC Manager & marks a workload domain for deletion.

createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryTry{$uri="https://$sddcManager/v1/domains/$id"$body='{"markForDeletion": true}'Invoke-RestMethod-MethodPATCH-URI$uri-ContentTypeapplication/json-headers$headers-body$body# This API does not return a response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionSet-VCFWorkloadDomain

.DESCRIPTION
Before a workload domain can be deleted it must first be marked for deletion. See Set-VCFWorkloadDomain
The Remove-VCFWorkloadDomain cmdlet connects to the specified SDDC Manager & deletes a workload domain.

createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryTry{$uri="https://$sddcManager/v1/domains/$id"$response=Invoke-RestMethod-MethodDELETE-URI$uri-headers$headers$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionRemove-VCFWorkloadDomain

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/sddc-federation"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFFederation

FunctionSet-VCFFederation{<#
.SYNOPSIS
Bootstrap a VMware Cloud Foundation to form a federation

.DESCRIPTION
The Set-VCFFederation cmdlet bootstraps the creation of a Federation in VCF

.EXAMPLE
PS C:\> Set-VCFFederation -json createFederation.json
This example shows how to create a fedration using the json file
#>

if(!(Test-Path$json)){Throw"JSON File Not Found"}else{Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$ConfigJson=(Get-Content-Raw$json)# Reads the json file contents into the $ConfigJson variable$uri="https://$sddcManager/v1/sddc-federation"$response=Invoke-RestMethod-MethodPUT-URI$uri-headers$headers-ContentTypeapplication/json-body$ConfigJson$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}}Export-ModuleMember-FunctionSet-VCFFederation

FunctionRemove-VCFFederation{<#
.SYNOPSIS
Remove VCF Federation

.DESCRIPTION
A function that ensures VCF Federation is empty and completely dismantles it.

createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/sddc-federation"Try{# Verify that SDDC Manager we're connected to is a controller and only one in the Federation$sddcs=Get-VCFFederation|Select-ObjectmemberDetailsForeach($sddcin$sddcs){if($sddc.memberDetails.role-eq"CONTROLLER"){$controller++if($sddc.memberDetails.role-eq"MEMBER"){$member++}}}if($controller-gt1){Throw"Only one controller can be present when dismantling VCF Federation. Remove additional controllers and try again"}if($member-gt0){Throw"VCF Federation members still exist. Remove all members and additional controllers before dismantling VCF Federation"}$response=Invoke-RestMethod-MethodDELETE-URI$uri-headers$headers$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionRemove-VCFFederation

######### Start APIs for managing Federation ##########

######### Start APIs for managing Hosts ##########

FunctionGet-VCFHost{<#
.SYNOPSIS
Connects to the specified SDDC Manager and retrieves a list of hosts.

.DESCRIPTION
The Get-VCFHost cmdlet connects to the specified SDDC Manager and retrieves a list of hosts.
VCF Hosts are defined by status
- ASSIGNED - Hosts that are assigned to a Workload domain
- UNASSIGNED_USEABLE - Hosts that are available to be assigned to a Workload Domain
- UNASSIGNED_UNUSEABLE - Hosts that are currently not assigned to any domain and can be used for other domain tasks after completion of cleanup operation

.EXAMPLE
PS C:\> Get-VCFHost
This example shows how to get all hosts regardless of status

.EXAMPLE
PS C:\> Get-VCFHost -Status ASSIGNED
This example shows how to get all hosts with a specific status

.EXAMPLE
PS C:\> Get-VCFHost -id edc4f372-aab5-4906-b6d8-9b96d3113304
This example shows how to get a host by id

.EXAMPLE
PS C:\> Get-VCFHost -fqdn sfo01-m01-esx01.sfo.rainpole.io
This example shows how to get a host by fqdn
#>

createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryTry{if(-not$PsBoundParameters.ContainsKey("status")-and(-not$PsBoundParameters.ContainsKey("id"))-and(-not$PsBoundParameters.ContainsKey("fqdn"))){$uri="https://$sddcManager/v1/hosts"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if($PsBoundParameters.ContainsKey("fqdn")){$uri="https://$sddcManager/v1/hosts"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements|Where-Object{$_.fqdn-eq$fqdn}}if($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/hosts/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}if($PsBoundParameters.ContainsKey("status")){$uri="https://$sddcManager/v1/hosts?status=$status"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFHost

FunctionCommission-VCFHost{<#
.SYNOPSIS
Connects to the specified SDDC Manager and commissions a list of hosts

.DESCRIPTION
The Commission-VCFHost cmdlet connects to the specified SDDC Manager and commissions a list of hosts
Host list spec is provided in a JSON file.

.EXAMPLE
PS C:\> Commission-VCFHost -json .\Host\commissionHosts\commissionHostSpec.json
This example shows how to commission a list of hosts based on the details provided in the JSON file

Try{validateJsonInput# Calls validateJsonInput Function to check the JSON file provided existscreateHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif(-Not$PsBoundParameters.ContainsKey("validate")){$response=Validate-CommissionHostSpec-json$ConfigJson# Validate the provided JSON input specification file$taskId=$response.id# Get the task id from the validation functionDo{# Keep checking until executionStatus is not IN_PROGRESS$uri="https://$sddcManager/v1/hosts/validations/$taskId"$response=Invoke-RestMethod-MethodGET-URI$uri-Headers$headers-ContentTypeapplication/json}While($response.executionStatus-eq"IN_PROGRESS")# Submit the commissiong job only if the JSON validation task finished with executionStatus=COMPLETED & resultStatus=SUCCEEDEDif($response.executionStatus-eq"COMPLETED"-and$response.resultStatus-eq"SUCCEEDED"){Write-Host"`n Task validation completed successfully, invoking host(s) commissioning on SDDC Manager `n"-ForegroundColorGreen$uri="https://$sddcManager/v1/hosts/"$response=Invoke-RestMethod-MethodPOST-URI$uri-headers$headers-ContentTypeapplication/json-body$ConfigJsonReturn$response}else{Write-Host"`n The validation task commpleted the run with the following problems: `n"-ForegroundColorYellowWrite-Host" "$response.validationChecks.errorResponse.message`n-ForegroundColorYellow}}elseif($PsBoundParameters.ContainsKey("validate")){$response=Validate-CommissionHostSpec-json$ConfigJson# Validate the provided JSON input specification file$taskId=$response.id# Get the task id from the validation functionDo{# Keep checking until executionStatus is not IN_PROGRESS$uri="https://$sddcManager/v1/hosts/validations/$taskId"$response=Invoke-RestMethod-MethodGET-URI$uri-Headers$headers-ContentTypeapplication/json}While($response.executionStatus-eq"IN_PROGRESS")if($response.executionStatus-eq"COMPLETED"-and$response.resultStatus-eq"SUCCEEDED"){Write-Host"`n Task validation completed successfully `n"-ForegroundColorGreenReturn$response}else{Write-Host"`n The validation task commpleted the run with the following problems: `n"-ForegroundColorYellowWrite-Host" "$response.validationChecks.errorResponse.message`n-ForegroundColorYellow}}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionCommission-VCFHost

FunctionDecommission-VCFHost{<#
.SYNOPSIS
Connects to the specified SDDC Manager and decommissions a list of hosts. Host list is provided in a JSON file.

.DESCRIPTION
The Decommission-VCFHost cmdlet connects to the specified SDDC Manager and decommissions a list of hosts.

.EXAMPLE
PS C:\> Decommission-VCFHost -json .\Host\decommissionHostSpec.json
This example shows how to decommission a set of hosts based on the details provided in the JSON file.
#>

if(!(Test-Path$json)){Throw"JSON File Not Found"}else{# Reads the json file contents into the $ConfigJson variable$ConfigJson=(Get-Content-Raw$json)createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/hosts"Try{$response=Invoke-RestMethod-MethodDELETE-URI$uri-headers$headers-ContentTypeapplication/json-body$ConfigJson$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}}Export-ModuleMember-FunctionDecommission-VCFHost

######### End APIs for managing Hosts ##########

######### Start APIs for managing License Keys ##########

FunctionGet-VCFLicenseKey{<#
.SYNOPSIS
Connects to the specified SDDC Manager and retrieves a list of License keys

.DESCRIPTION
The Get-VCFLicenseKey cmdlet connects to the specified SDDC Manager and retrieves a list of License keys

.EXAMPLE
PS C:\> Get-VCFLicenseKey
This example shows how to get a list of all License keys

.EXAMPLE
PS C:\> Get-VCFLicenseKey -key "AAAAA-AAAAA-AAAAA-AAAAA-AAAAA"
This example shows how to get a specified License key

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif($PsBoundParameters.ContainsKey("key")){$uri="https://$sddcManager/v1/license-keys/$key"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}if($PsBoundParameters.ContainsKey("productType")){$uri="https://$sddcManager/v1/license-keys?productType=$productType"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if($PsBoundParameters.ContainsKey("status")){$uri="https://$sddcManager/v1/license-keys?licenseKeyStatus=$status"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if(-not$PsBoundParameters.ContainsKey("key")-and(-not$PsBoundParameters.ContainsKey("productType"))-and(-not$PsBoundParameters.ContainsKey("status"))){$uri="https://$sddcManager/v1/license-keys"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFLicenseKey

FunctionNew-VCFLicenseKey{<#
.SYNOPSIS
Connects to the specified SDDC Manager and adds a new License Key.

.DESCRIPTION
The New-VCFLicenseKey cmdlet connects to the specified SDDC Manager and adds a new License Key.

if(!(Test-Path$json)){Throw"JSON File Not Found"}else{$ConfigJson=(Get-Content$json)# Read the createNetworkPool json file contents into the $ConfigJson variablecreateHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/license-keys"Try{Invoke-RestMethod-MethodPOST-URI$uri-headers$headers-ContentTypeapplication/json-body$ConfigJson# This API does not return a response body. Sending GET to validate the License Key creation was successful$license=$ConfigJson|ConvertFrom-Json$licenseKey=$license.keyGet-VCFLicenseKey-key$licenseKey}Catch{ResponseException# Call ResponseException function to get error response from the exception}}}Export-ModuleMember-FunctionNew-VCFLicenseKey

FunctionRemove-VCFLicenseKey{<#
.SYNOPSIS
Connects to the specified SDDC Manager and deletes a license key.

.DESCRIPTION
The Remove-VCFLicenseKey cmdlet connects to the specified SDDC Manager and deletes a License Key.
A license Key can only be removed if it is not in use.

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/license-keys/$key"Invoke-RestMethod-MethodDELETE-URI$uri-headers$headers# This API does not return a response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionRemove-VCFLicenseKey

######### End APIs for managing License Keys ##########

######### Start APIs for managing Members of the Federation ##########

FunctionGet-VCFFederationMember{<#
.SYNOPSIS
Gets members of the Federation

createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/sddc-federation/members"Try{$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headersif(!$response.federationName){Throw"Failed to get members, no Federation found."}else{$response}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFFederationMember

FunctionNew-VCFFederationInvite{<#
.SYNOPSIS
Invite new member to VCF Federation.

.DESCRIPTION
The New-VCFFederationInvite cmdlet creates a new invitation for a member to join the existing VCF Federation.

.EXAMPLE
PS C:\> New-VCFFederationInvite -inviteeFqdn lax-vcf01.lax.rainpole.io
This example demonstrates how to create an invitation for a specified VCF Manager from the Federation controller.
#>

createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/sddc-federation/membership-tokens"Try{$sddcMemberRole=Get-VCFFederationMembersif($sddcMemberRole.memberDetail.role-ne"CONTROLLER"-and$sddcMemberRole.memberDetail.fqdn-ne$sddcManager){Throw"$sddcManager is not the Federation controller. Invitatons to join Federation can only be sent from the Federation controller."}else{$inviteeDetails=@{inviteeRole='MEMBER'inviteeFqdn=$inviteeFqdn}$ConfigJson=$inviteeDetails|ConvertTo-Json$response=Invoke-RestMethod-MethodPOST-URI$uri-headers$headers-body$ConfigJson-ContentType'application/json'$response}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionNew-VCFFederationInvite

if(!(Test-Path$json)){Throw"JSON File Not Found"}else{$ConfigJson=(Get-Content-Raw$json)# Reads the joinSVCFFederation json file contents into the $ConfigJson variablecreateHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/sddc-federation/members"Try{$response=Invoke-RestMethod-MethodPOST-URI$uri-headers$headers-ContentType'application/json'-body$ConfigJson$response$taskId=$response.taskId# get the task id from the action# keep checking until executionStatus is not IN_PROGRESSDo{$uri="https://$sddcManager/v1/sddc-federation/tasks/$taskId"$response=Invoke-RestMethod-MethodGET-URI$uri-Headers$headers-ContentType'application/json'Start-Sleep-Second5}While($response.status-eq"IN_PROGRESS")$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}}Export-ModuleMember-FunctionJoin-VCFFederation

######### End APIs for managing Members of the Federation ##########

######### Start APIs for managing NSX-T Clusters ##########

FunctionGet-VCFNsxtCluster{<#
.SYNOPSIS
Gets a list of NSX-T Clusters

.DESCRIPTION
The Get-VCFNsxtCluster cmdlet retrieves a list of NSX-T Clusters managed by the connected SDDC Manager

.EXAMPLE
PS C:\> Get-VCFNsxtCluster
This example shows how to get the list of NSX-T Clusters managed by the connected SDDC Manager

.EXAMPLE
PS C:\> Get-VCFNsxtCluster -id d189a789-dbf2-46c0-a2de-107cde9f7d24
This example shows how to return the details for a specic NSX-T Clusters managed by the connected SDDC Manager
using the ID

.EXAMPLE
PS C:\> Get-VCFNsxtCluster | select vipfqdn
This example shows how to get the list of NSX-T Clusters managed by the connected SDDC Manager but only return the vipfqdn
#>

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif(-not$PsBoundParameters.ContainsKey("id")-and(-not$PsBoundParameters.ContainsKey("domainId"))){$uri="https://$sddcManager/v1/nsxt-clusters"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/nsxt-clusters/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFNsxtCluster

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif(-not$PsBoundParameters.ContainsKey("name")-and(-not$PsBoundParameters.ContainsKey("id"))){$uri="https://$sddcManager/v1/network-pools"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/network-pools/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}if($PsBoundParameters.ContainsKey("name")){$uri="https://$sddcManager/v1/network-pools"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements|Where-Object{$_.name-eq$name}}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFNetworkPool

Try{validateJsonInput# Calls validateJsonInput Function to check the JSON file provided existscreateHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/network-pools"Invoke-RestMethod-MethodPOST-URI$uri-headers$headers-ContentTypeapplication/json-body$ConfigJson# This API does not return a response body. Sending GET to validate the Network Pool creation was successful$validate=$ConfigJson|ConvertFrom-Json$poolName=$validate.nameGet-VCFNetworkPool-name$poolName}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionNew-VCFNetworkPool

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/network-pools/$id"Invoke-RestMethod-MethodDELETE-URI$uri-headers$headers# This API does not return a response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionRemove-VCFNetworkPool

FunctionGet-VCFNetworkIPPool{<#
.SYNOPSIS
Get a Network of a Network Pool

.DESCRIPTION
The Get-VCFNetworkIPPool cmdlet connects to the specified SDDC Manager and retrieves a list of the networks
configured for the provided network pool.

.EXAMPLE
PS C:\> Get-VCFNetworkIPPool -id 917bcf8f-93e8-4b84-9627-471899c05f52
This example shows how to get a list of all networks associated to the network pool based on the id provided

.EXAMPLE
PS C:\> Get-VCFNetworkIPPool -id 917bcf8f-93e8-4b84-9627-471899c05f52 -networkid c2197368-5b7c-4003-80e5-ff9d3caef795
This example shows how to get a list of details for a specific network associated to the network pool using ids
#>

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/network-pools/$id/networks"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if($PsBoundParameters.ContainsKey("id")-and($PsBoundParameters.ContainsKey("networkid"))){$uri="https://$sddcManager/v1/network-pools/$id/networks/$networkid"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFNetworkIPPool

FunctionAdd-VCFNetworkIPPool{<#
.SYNOPSIS
Add an IP Pool to the Network of a Network Pool

.DESCRIPTION
The Add-VCFNetworkIPPool cmdlet connects to the specified SDDC Manager and adds a new IP Pool
to an existing Network within a Network Pool.

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/network-pools/$id/networks/$networkid/ip-pools"$body='{"end": "'+$ipEnd+'","start": "'+$ipStart+'"}'$response=Invoke-RestMethod-MethodPOST-URI$uri-headers$headers-ContentTypeapplication/json-body$body$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionAdd-VCFNetworkIPPool

FunctionRemove-VCFNetworkIPPool{<#
.SYNOPSIS
Remove an IP Pool from the Network of a Network Pool

.DESCRIPTION
The Remove-VCFNetworkIPPool cmdlet connects to the specified SDDC Manager and removes an IP Pool assigned to an
existing Network within a Network Pool.

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/network-pools/$id/networks/$networkid/ip-pools"$body='{"end": "'+$ipEnd+'","start": "'+$ipStart+'"}'$response=Invoke-RestMethod-MethodDELETE-URI$uri-headers$headers-ContentTypeapplication/json-body$body$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionRemove-VCFNetworkIPPool

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif(-not$PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/edge-clusters"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/edge-clusters/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFEdgeCluster

Try{validateJsonInput# Calls validateJsonInput Function to check the JSON file provided existscreateHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif(-Not$PsBoundParameters.ContainsKey("validate")){$response=Validate-EdgeClusterSpec-json$ConfigJson# Validate the provided JSON input specification file$taskId=$response.id# Get the task id from the validation functionDo{# Keep checking until executionStatus is not IN_PROGRESS$uri="https://$sddcManager/v1/edge-clusters/validations/$taskId"$response=Invoke-RestMethod-MethodGET-URI$uri-Headers$headers-ContentTypeapplication/json}While($response.executionStatus-eq"IN_PROGRESS")# Submit the commissiong job only if the JSON validation task finished with executionStatus=COMPLETED & resultStatus=SUCCEEDEDif($response.executionStatus-eq"COMPLETED"-and$response.resultStatus-eq"SUCCEEDED"){Write-Host"`n Task validation completed successfully, invoking NSX-T Edge Cluster Creation on SDDC Manager `n"-ForegroundColorGreen$uri="https://$sddcManager/v1/edge-clusters"$response=Invoke-RestMethod-MethodPOST-URI$uri-ContentTypeapplication/json-headers$headers-body$ConfigJsonReturn$response}else{Write-Host"`n The validation task commpleted the run with the following problems: `n"-ForegroundColorYellowWrite-Host$response.validationChecks.errorResponse.message`n-ForegroundColorYellow}}elseif($PsBoundParameters.ContainsKey("validate")){$response=Validate-EdgeClusterSpec-json$ConfigJson# Validate the provided JSON input specification file$taskId=$response.id# Get the task id from the validation functionDo{# Keep checking until executionStatus is not IN_PROGRESS$uri="https://$sddcManager/v1/edge-clusters/validations/$taskId"$response=Invoke-RestMethod-MethodGET-URI$uri-Headers$headers-ContentTypeapplication/json}While($response.executionStatus-eq"IN_PROGRESS")if($response.executionStatus-eq"COMPLETED"-and$response.resultStatus-eq"SUCCEEDED"){Write-Host"`n Task validation completed successfully `n"-ForegroundColorGreenReturn$response}else{Write-Host"`n The validation task commpleted the run with the following problems: `n"-ForegroundColorYellowWrite-Host" "$response.validationChecks.errorResponse.message`n-ForegroundColorYellow}}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionNew-VCFEdgeCluster

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif(-not$PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/personalities"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/personalities/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFPersonality

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/sddc-federation/tasks/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFFederationTask

######### End APIs for managing Federation Tasks ##########

######### Start APIs for managing SDDC (Cloud Builder) ##########

FunctionGet-CloudBuilderSDDC{<#
.SYNOPSIS
Retrieve all SDDCs

.DESCRIPTION
The Get-CloudBuilderSDDC cmdlet gets a list of SDDC deployments from Cloud Builder

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/sddc-managers/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}if(-not$PsBoundParameters.ContainsKey("id")-and(-not$PsBoundParameters.ContainsKey("domainId"))){$uri="https://$sddcManager/v1/sddc-managers"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if($PsBoundParameters.ContainsKey("domainId")){$uri="https://$sddcManager/v1/sddc-managers/?domain=$domainId"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFManager

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/system/prechecks/tasks/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-ContentTypeapplication/json-headers$headers$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFSystemPrecheckTask

######### End APIs for managing System Prechecks ##########

######### Start APIs for managing Tasks ##########

FunctionGet-VCFTask{<#
.SYNOPSIS
Connects to the specified SDDC Manager and retrieves a list of tasks.

.DESCRIPTION
The Get-VCFTask cmdlet connects to the specified SDDC Manager and retrieves a list of tasks.

.EXAMPLE
PS C:\> Get-VCFTask
This example shows how to get all tasks

.EXAMPLE
PS C:\> Get-VCFTask -id 7e1c2eee-3177-4e3b-84db-bfebc83f386a
This example shows how to get a task by id

.EXAMPLE
PS C:\> Get-VCFTask -status SUCCESSFUL
This example shows how to get all tasks with a status of SUCCESSFUL
#>

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif(-not$PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/tasks/"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/tasks/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}if($PsBoundParameters.ContainsKey("status")){$uri="https://$sddcManager/v1/tasks/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements|Where-Object{$_.status-eq$status}}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFTask

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/tasks/$id"$response=Invoke-RestMethod-MethodPATCH-URI$uri-headers$headers}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionRestart-VCFTask

#### End APIs for managing Tasks #####

######### Start APIs for managing Access and Refresh Token ##########

######### End APIs for managing Access and Refresh Token ##########

######### Start APIs for managing Upgradables ##########

FunctionGet-VCFUpgradable{<#
.SYNOPSIS
Get the Upgradables

.DESCRIPTION
Fetches the list of Upgradables in the System. Only one Upgradable becomes AVAILABLE for Upgrade.
The Upgradables provides information that can be use for Precheck API and also in the actual Upgrade API call.

.EXAMPLE
PS C:\> Get-VCFUpgradable
This example shows how to retrieve the list of upgradables in the system
#>

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/system/upgradables"$response=Invoke-RestMethod-MethodGET-URI$uri-ContentTypeapplication/json-headers$headers$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFUpgradable

######### End APIs for managing Upgradables ##########

######### Start APIs for managing Upgrades ##########

######### End APIs for managing Upgrades ##########

######### Start APIs for managing Users ##########

FunctionGet-VCFUser{<#
.SYNOPSIS
Get all Users

.DESCRIPTION
The Get-VCFUser cmdlet gets a list of users in SDDC Manager

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/users"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFUser

FunctionNew-VCFUser{<#
.SYNOPSIS
Connects to the specified SDDC Manager and adds a new user.

.DESCRIPTION
The New-VCFUser cmdlet connects to the specified SDDC Manager and adds a new user with a specified role.

.EXAMPLE
PS C:\> New-VCFUser -user vcf-admin@rainpole.io -role ADMIN
This example shows how to add a new user with a specified role
#>

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/roles"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFRole

FunctionRemove-VCFUser{<#
.SYNOPSIS
Deletes a user from SDDC Manager

.DESCRIPTION
The Remove-VCFUser cmdlet connects to the specified SDDC Manager and deletes a user

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/users/$id"$response=Invoke-RestMethod-MethodDELETE-URI$uri-headers$headers-ContentTypeapplication/json$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionRemove-VCFUser

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/vcf-services/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}if(-not$PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/vcf-services"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFService

######### End APIs for managing Version Alias Configuration ##########

######### Start APIs for managing DNS & NTP Configuration ##########

######### End APIs for managing DNS & NTP Configuration ##########

######### Start APIs for managing vCenters ##########

FunctionGet-VCFvCenter{<#
.SYNOPSIS
Gets a list of vCenter Servers

.DESCRIPTION
Retrieves a list of vCenter Servers managed by the connected SDDC Manager

.EXAMPLE
PS C:\> Get-VCFvCenter
This example shows how to get the list of vCenter Servers managed by the connected SDDC Manager

.EXAMPLE
PS C:\> Get-VCFvCenter -id d189a789-dbf2-46c0-a2de-107cde9f7d24
This example shows how to return the details for a specific vCenter Server managed by the connected SDDC Manager
using its id

.EXAMPLE
PS C:\> Get-VCFvCenter -domain 1a6291f2-ed54-4088-910f-ead57b9f9902
This example shows how to return the details off all vCenter Server managed by the connected SDDC Manager using
its domainId

.EXAMPLE
PS C:\> Get-VCFvCenter | select fqdn
This example shows how to get the list of vCenter Servers managed by the connected SDDC Manager but only return the fqdn
#>

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessaryif(-not$PsBoundParameters.ContainsKey("id")-and(-not$PsBoundParameters.ContainsKey("domainId"))){$uri="https://$sddcManager/v1/vcenters"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}if($PsBoundParameters.ContainsKey("id")){$uri="https://$sddcManager/v1/vcenters/$id"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}if($PsBoundParameters.ContainsKey("domainId")){$uri="https://$sddcManager/v1/vcenters/?domain=$domainId"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response.elements}}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFvCenter

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/vrslcm"$response=Invoke-RestMethod-MethodGET-URI$uri-headers$headers$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionGet-VCFvRSLCM

Try{createHeader# Call createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/vrslcm"$response=Invoke-RestMethod-MethodDELETE-URI$uri-headers$headers$response}Catch{# Call ResponseException function to get error response from the exceptionResponseException}}Export-ModuleMember-FunctionRemove-VCFvRSLCM

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/vrslcm"$response=Invoke-RestMethod-MethodPATCH-URI$uri-headers$headers$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}Export-ModuleMember-FunctionReset-VCFvRSLCM

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/hosts/validations"$response=Invoke-RestMethod-MethodPOST-URI$uri-ContentTypeapplication/json-headers$headers-body$jsonReturn$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}

FunctionValidate-WorkloadDomainSpec{

Param([Parameter(Mandatory=$true)][object]$json)

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/domains/validations"$response=Invoke-RestMethod-MethodPOST-URI$uri-ContentTypeapplication/json-headers$headers-body$jsonReturn$response}Catch{ResponseException# Call ResponseException function to get error response from the exception}}

FunctionValidate-VCFClusterSpec{

Param([Parameter(Mandatory=$true)][object]$json)

createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/clusters/validations"Try{$response=Invoke-RestMethod-MethodPOST-URI$uri-ContentTypeapplication/json-headers$headers-body$json}Catch{ResponseException# Call ResponseException function to get error response from the exception}Return$response}

createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/clusters/$clusterid/validations"Try{$response=Invoke-RestMethod-MethodPOST-URI$uri-ContentTypeapplication/json-headers$headers-body$json}Catch{ResponseException# Call ResponseException function to get error response from the exception}Return$response}

FunctionValidate-EdgeClusterSpec{

Param([Parameter(Mandatory=$true)][object]$json)

Try{createHeader# Calls createHeader function to set Accept & AuthorizationcheckVCFToken# Calls the CheckVCFToken function to validate the access token and refresh if necessary$uri="https://$sddcManager/v1/edge-clusters/validations"$response=Invoke-RestMethod-MethodPOST-URI$uri-ContentTypeapplication/json-headers$headers-body$json}Catch{ResponseException# Call ResponseException function to get error response from the exception}Return$response}

# Convert Expiry time to PowerShell DateTime$orig=(Get-Date-Year1970-Month1-Day1-hour0-Minute0-Second0-Millisecond0)$timeZone=Get-TimeZone$utcTime=$orig.AddSeconds($decodedToken.exp)$hoursOffset=$timeZone.GetUtcOffset($(Get-Date)).hours#Daylight saving needs to be calculated$localTime=$utcTime.AddHours($hoursOffset)# Return local time,$decodedToken|Add-Member-TypeNoteProperty-Name"expiryDateTime"-Value$localTime

# Time to Expiry$timeToExpiry=($localTime-(get-date))$decodedToken|Add-Member-TypeNoteProperty-Name"timeToExpiry"-Value$timeToExpiry

.DESCRIPTION
The Invoke-VCFCommand cmdlet connects to the specified SDDC Manager via SSH using vcf user and subsequently
execute elevated SOS commands using the root account. Both vcf and root password are mandatory parameters.
If passwords are not passed as parameters it will prompt for them.

.EXAMPLE
PS C:\> Invoke-VCFCommand -sosOption general-health
This example will ask for vcf and root password to the user and then execute and display the output of "/opt/vmware/sddc-support/sos --general-health"
#>

FunctionResolve-PSModule{<#
.SYNOPSIS
Check for a PowerShell module presence, if not there try to import/install it.

.DESCRIPTION
This function is not exported. The idea is to use the return searchResult from the caller function to establish
if we can proceed to the next step where the module will be required (developed to check on Posh-SSH).
Logic:
- Check if module is imported into the current session
- If module is not imported, check if available on disk and try to import
- If module is not imported & not available on disk, try PSGallery then install and import
- If module is not imported, not available and not in online gallery then abort

Informing user only if the module needs importing/installing. If the module is already present nothing will be displayed.

.EXAMPLE
PS C:\> $poshSSH = Resolve-PSModule -moduleName "Posh-SSH"
This example will check if the current PS module session has Posh-SSH installed, if not will try to install it
#>

# check if module is imported into the current sessionif(Get-Module-Name$moduleName){$searchResult="ALREADY_IMPORTED"}else{# If module is not imported, check if available on disk and try to importif(Get-Module-ListAvailable|Where-Object{$_.Name-eq$moduleName}){Try{"`n Module $moduleName not loaded, importing now please wait..."Import-Module$moduleNameWrite-Host" Module $moduleName imported successfully."$searchResult="IMPORTED"}Catch{$searchResult="IMPORT_FAILED"}}else{# If module is not imported & not available on disk, try PSGallery then install and importif(Find-Module-Name$moduleName|Where-Object{$_.Name-eq$moduleName}){Try{Write-Host"`n Module $moduleName was missing, installing now please wait..."Install-Module-Name$moduleName-Force-ScopeCurrentUserWrite-Host" Importing module $moduleName, please wait..."Import-Module$moduleNameWrite-Host" Module $moduleName installed and imported"$searchResult="INSTALLED_IMPORTED"}Catch{$searchResult="INSTALLIMPORT_FAILED"}}else{# If module is not imported, not available and not in online gallery then abort$searchResult="NOTAVAILABLE"}}}Return$searchResult}

FunctionvalidateJsonInput{if(!(Test-Path$json)){Throw"JSON file provided not found, please try again"}else{$Global:ConfigJson=(Get-Content-Raw$json)# Read the json file contents into the $ConfigJson variableWrite-Verbose"JSON file found and content has been read into a variable"Write-Verbose$ConfigJson}}