Skip to content

Commit

Permalink
Added cmdlet for setting Admin Password
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBegg committed Aug 31, 2020
1 parent 68731c6 commit 39e671e
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 5 deletions.
105 changes: 105 additions & 0 deletions Public/Operations/Set-VCDSProviderAdminPassword.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
function Set-VCDSProviderAdminPassword(){
<#
.SYNOPSIS
Reset the Provider Administrator account password for a Cloud Director service instance.
.DESCRIPTION
Reset the Provider Administrator account password for a Cloud Director service instance.
.PARAMETER InstanceId
The Cloud Director Instance Id
.PARAMETER InstanceName
The Cloud Director Instance Name
.PARAMETER NewProviderAdminPassword
The Password to set as the Provider Administrator account password for the provided Cloud Director instance
.PARAMETER EnvironmentId
Optionally The Cloud Director Service Environment Id (Default is used if none is provided)
.EXAMPLE
Set-VCDSProviderAdminPassword -InstanceName "CloudDirector-TestInstance-01" -NewProviderAdminPassword "SuperSt0rngP@ssword!"
Resets the administrator user password for the instance named "CloudDirector-TestInstance-01" in the CDS default environment to "SuperSt0rngP@ssword!"
.NOTES
AUTHOR: Adrian Begg
LASTEDIT: 2020-08-31
VERSION: 1.0
#>
[CmdletBinding(DefaultParameterSetName="ByInstanceId")]
Param(
[Parameter(Mandatory=$True, ParameterSetName="ByInstanceId")]
[ValidateNotNullorEmpty()] [string] $InstanceId,
[Parameter(Mandatory=$True, ParameterSetName="ByInstanceName")]
[ValidateNotNullorEmpty()] [string] $InstanceName,
[Parameter(Mandatory=$True, ParameterSetName="ByInstanceId")]
[Parameter(Mandatory=$True, ParameterSetName="ByInstanceName")]
[ValidateNotNullorEmpty()] [string] $NewProviderAdminPassword,
[Parameter(Mandatory=$False)]
[ValidateNotNullorEmpty()] [String] $EnvironmentId
)
if(!$global:VCDService.IsConnected){
throw "You are not currently connected to the VMware Console Services Portal (CSP) for VMware Cloud Director Service. Please use Connect-VCDService cmdlet to connect to the service and try again."
}
# Next check if the EnvironmentId has been provided and is valid
if($PSBoundParameters.ContainsKey("EnvironmentId")){
$Environment = $global:VCDService.VCDSEnvironments | Where-Object {$_.id -eq $EnvironmentId}
if($Environment.count -eq 0){
throw "An VCDS Environment with the Id $EnvironmentId can not be found. Please check the Id and try again."
}
} else {
$Environment = $global:VCDService.DefaultEnvironment
}
# Setup a Service URI for the environment
$ServiceURI = $Environment.url

if($PSCmdlet.ParameterSetName -eq "ByInstanceName"){
# Check if an instance already exists with the provided Name
$Instance = Get-VCDSInstances -EnvironmentId $Environment.id -Name $InstanceName
if($Instance.count -eq 0){
throw "An instance with the Name $InstanceName can not be found in the environment with the Id $($Environment.id) please check the Name and try again."
}
}
if($PSCmdlet.ParameterSetName -eq "ByInstanceId") {
# Check if an instance already exists with the provided Id
$Instance = Get-VCDSInstances -EnvironmentId $Environment.id -Id $InstanceId
if($Instance.count -eq 0){
throw "An instance with the Id $InstanceId can not be found in the environment with the Id $($Environment.id) please check the Name and try again."
}
}

# Setup a HashTable for the API call to the Cloud Gateway
$InstanceOperationAPIEndpoint = "$ServiceURI/environment/$($Environment.id)/instances/$($Instance.id)/operations/invoke"
[Hashtable] $htPayload = @{
operationType = "resetProviderAdminPassword"
arguments = @{}
}

# Set the arguments to reset the password
[Hashtable] $htArguments = @{
providerAdminNewPassword = $NewProviderAdminPassword
providerAdminNewPasswordConfirm = $NewProviderAdminPassword
}
# Set the arguments to the Payload
$htPayload.arguments = $htArguments

# A Hashtable of Request Parameters
[Hashtable] $RequestParameters = @{
URI = $InstanceOperationAPIEndpoint
Method = "Post"
ContentType = "application/json"
Headers = @{
"Authorization" = "Bearer $($global:VCDService.AccessToken)"
"Accept" = "application/json"
}
Body = (ConvertTo-Json $htPayload)
UseBasicParsing = $true
}
try{
$SetInstancePassword = ((Invoke-WebRequest @RequestParameters).Content | ConvertFrom-Json)
return $SetInstancePassword
} catch {
throw "An exception has occurred attempting to make the API call. $_"
}
}
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# VMware.CDS.Community
A PowerShell module to interact with the VMware Cloud Director service (Early Access) using the VMware Cloud Services Portal (CSP).
A PowerShell module to interact with the VMware Cloud Director service (Initial Access Release) using the VMware Cloud Services Portal (CSP).

**Please Note**: This is a community supported module. It is not provided by, affiliated with or supported by VMware.

## Project Owner
Adrian Begg (@AdrianBegg)

## Tested Versions
* PowerShell Core: 7.0.0
* VMware Cloud Director service (Early Access Release 7/7/2020)
* PowerShell Core: 7.0.3
* VMware Cloud Director service (Initial Access Release 22 May 2020)

## Functional Coverage
The following cmdlets are available in the current release.
Expand All @@ -27,9 +27,18 @@ The following cmdlets are available in the current release.
* New-VCDSSupportBundle : Generates a Cloud Director support bundle
* Register-VCDSSDDC : Associate an VMC SDDC with a VMware Cloud Director service instance.
* Set-VCDSDomain : Configures a Custom DNS name and X.509 SSL certificates for a Cloud Director service instance and Console Proxy endpoints.
* Set-VCDSProviderAdminPassword : Sets a new password for the administrator user of a Cloud Director service instance.

### Administration:
* Get-VCDSTasks : Returns a collection of Tasks from the connected Cloud Director Service environment.
* Watch-VCDSTaskCompleted : A helper function to monitor a running task and returns True when the task completes.

All of the cmdlets in the module should have well described PowerShell help available. For detailed help including examples please use `Get-help <cmdlet> -Detailed` (e.g. `Get-help New-VCDSInstance -Detailed`).
All of the cmdlets in the module should have well described PowerShell help available. For detailed help including examples please use `Get-help <cmdlet> -Detailed` (e.g. `Get-help New-VCDSInstance -Detailed`).

### Change Log
**v0.2 - Initial release (31st August 2020)**
* Added cmdlet for resetting Provider Administrator password
* Added support for using cmdlets when VMware Cloud Organization has access to multiple CDS environments (e.g. Initial Availability us-west, Initial Availability eu-central-1)

**v0.1 - Initial release (7th July 2020)**
* Initial public release
Binary file modified VMware.CDS.Community.psd1
Binary file not shown.
2 changes: 1 addition & 1 deletion build/CreateModuleManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $colPublicFunctions = ($colPublicFunctionFiles | Where-Object {$_.Extension -eq

$manifest = @{
Path = "$BasePath\VMware.CDS.Community.psd1"
ModuleVersion = '0.1'
ModuleVersion = '0.2'
Author = 'Adrian Begg'
Copyright = '2020 Adrian Begg. All rights reserved.'
Description = 'A PowerShell module to interact with the VMware Cloud Director service using the VMware Cloud Services Portal (CSP).'
Expand Down

0 comments on commit 39e671e

Please sign in to comment.