Merge pull request #73 from ZertoPublic/UpdateServiceAccountPassword

Create function to Update service account password
This commit is contained in:
Wes Carroll
2020-04-07 10:44:00 -04:00
committed by GitHub
4 changed files with 175 additions and 0 deletions
+1
View File
@@ -12,6 +12,7 @@
* Updated the `Install-ZertoVra` logic to ensure that the target datastore is available on the target host. There isn't currently any method to validate the target network, but if that becomes available in a later version of the API, the function will be updated.
* Updated the `Install-ZertoVra` function to allow for installation of the VRA using the host password method. Please review the [Install-ZertoVra](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Install-ZertoVra.md) documentation for syntax and examples.
* Updated the `Edit-ZertoVra` function to allow for modification of the associated ESX host password if the need arises. Please review the [Edit-ZertoVra](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Edit-ZertoVra.md) documentation for syntax and examples.
* Added a new function, `Set-ZertoUserCredential`, to allow the updating of the username and password used to connect the Zerto Virtual Manager to the paired hypervisor. Please see the [Set-ZertoUserCredential](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Set-ZertoUserCredential.md) help for additional information.
### Zerto Analytics
@@ -0,0 +1,42 @@
#Requires -Modules Pester
$global:here = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$global:function = ((Split-Path -leaf $MyInvocation.MyCommand.Path).Split('.'))[0]
Describe $global:function -Tag 'Unit', 'Source', 'Built' {
InModuleScope -ModuleName ZertoApiWrapper {
Context "$global:function::Parameter Unit Tests" {
BeforeAll {
$script:ScriptBlock = (Get-Command $global:function).ScriptBlock
}
It "$global:function should have exactly 14 parameters defined" {
(Get-Command $global:function).Parameters.Count | Should -Be 14
}
$ParameterTestCases = @(
@{ParameterName = 'UserCredential'; Type = 'pscredential'; Mandatory = $true }
)
It "<ParameterName> parameter is of <Type> type" -TestCases $ParameterTestCases {
param($ParameterName, $Type, $Mandatory, $Validation)
Get-Command $global:function | Should -HaveParameter $ParameterName -Mandatory:$Mandatory -Type $Type
}
It "Supports 'SupportsShouldProcess'" {
Get-Command $global:function | Should -HaveParameter WhatIf
Get-Command $global:function | Should -HaveParameter Confirm
$script:ScriptBlock | Should -match 'SupportsShouldProcess'
$script:ScriptBlock | Should -match '\$PSCmdlet\.ShouldProcess\(.+\)'
}
}
Context "$global:function::Parameter Functional Tests" {
}
}
}
Remove-Variable -Name here -Scope Global
Remove-Variable -Name function -Scope Global
@@ -0,0 +1,35 @@
<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>
function Set-ZertoUserCredential {
[cmdletbinding(
SupportsShouldProcess,
ConfirmImpact = 'High'
)]
param(
[Parameter(
HelpMessage = "PSCredential Object that contains the username and password for the updated credentials.",
Mandatory
)]
[pscredential]$UserCredential
)
begin {
}
process {
$uri = '/localsite/virtualizationsettings'
$body = @{
Credentials = @{
UserName = $UserCredential.UserName
Password = $UserCredential.GetNetworkCredential().Password
}
}
if ( $PSCmdlet.ShouldProcess( $script:zvmServer, "Updating hypervisor service account credentials" )) {
Invoke-ZertoRestRequest -uri $uri -Method PUT -body ($body | ConvertTo-Json)
}
}
end {
}
}
+97
View File
@@ -0,0 +1,97 @@
---
external help file: ZertoApiWrapper-help.xml
Module Name: ZertoApiWrapper
online version: https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Set-ZertoUserCredential.md
schema: 2.0.0
---
# Set-ZertoUserCredential
## SYNOPSIS
Allows the change or update of the credentials used to allow the Zerto Virtual Manager to connect and communicate with the paired Hypervisor.
## SYNTAX
```
Set-ZertoUserCredential [-UserCredential] <PSCredential> [-WhatIf] [-Confirm] [<CommonParameters>]
```
## DESCRIPTION
Allows the change or update of the credentials used to allow the Zerto Virtual Manager to connect and communicate with the paired Hypervisor. A PSCredential object is required and will be used to pass the updated credentials.
## EXAMPLES
### Example 1
```powershell
PS C:\> Set-ZertoUserCredential -UserCredential $UserCredential
```
Will update the user account used to connect the Zerto Virtual Manager to the the paired Hypervisor.
### Example 2
```powershell
PS C:\> Set-ZertoUserCredential -UserCredential $UserCredential -Confirm:$False
```
Will update the user account used to connect the Zerto Virtual Manager to the the paired Hypervisor. CAUTION: By adding the `-Confirm:$False` parameter, this will suppress the confirmation dialog and you will not be prompted if you wish to complete this action.
## PARAMETERS
### -UserCredential
PSCredential Object that contains the username and password for the updated credentials.
```yaml
Type: PSCredential
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Confirm
Prompts you for confirmation before running the cmdlet.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -WhatIf
Shows what would happen if the cmdlet runs.
The cmdlet is not run.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
## OUTPUTS
## NOTES
## RELATED LINKS
[PSCredential Object Information](https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.pscredential)