diff --git a/RELEASENOTES.md b/RELEASENOTES.md index d3c968b..0c8b2f3 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -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 diff --git a/Tests/Public/Set-ZertoUserCredential.Tests.ps1 b/Tests/Public/Set-ZertoUserCredential.Tests.ps1 new file mode 100644 index 0000000..4cca845 --- /dev/null +++ b/Tests/Public/Set-ZertoUserCredential.Tests.ps1 @@ -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 " parameter is of 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 diff --git a/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 b/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 new file mode 100644 index 0000000..110be91 --- /dev/null +++ b/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 @@ -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 { + + } +} diff --git a/docs/Set-ZertoUserCredential.md b/docs/Set-ZertoUserCredential.md new file mode 100644 index 0000000..9fd7d20 --- /dev/null +++ b/docs/Set-ZertoUserCredential.md @@ -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] [-WhatIf] [-Confirm] [] +``` + +## 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)