From df83277c066cb7293b0a5de58401ce008fb4a5da Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 6 Apr 2020 17:15:52 -0400 Subject: [PATCH 1/9] Create Set-ZertoUserCredential.ps1 --- .../Public/Set-ZertoUserCredential.ps1 | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 diff --git a/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 b/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 new file mode 100644 index 0000000..71495b3 --- /dev/null +++ b/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 @@ -0,0 +1,33 @@ +<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> +function Set-ZertoUserCredential { + [cmdletbinding( + SupportsShouldProcess, + ConfirmImpact = 'High' + )] + param( + [Parameter( + HelpMessage = "PSCredential Object that conatins the username and password for the updated credentials.", + Mandatory + )] + [pscredential]$UserCredential + ) + + begin { + + } + + process { + $uri = '/localsite/virtualizationsettings' + $body = @{ + UserName = $UserCredential.UserName + Password = $UserCredential.GetNetworkCredential().Password + } + if ( $PSCmdlet.ShouldProcess( $script:zertoServer, "Updating hypervisor service account credentials" )) { + Invoke-ZertoRestRequest -uri $uri -Method PUT -body ($body | ConvertTo-Json) + } + } + + end { + + } +} From 536a62f792cdafd64a85329de543cf252672914b Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 6 Apr 2020 17:15:57 -0400 Subject: [PATCH 2/9] Create Set-ZertoUserCredential.Tests.ps1 --- .../Public/Set-ZertoUserCredential.Tests.ps1 | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Tests/Public/Set-ZertoUserCredential.Tests.ps1 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 From f34f21bb85c4395d6d97e47105e008134c8cfa78 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 7 Apr 2020 07:49:13 -0400 Subject: [PATCH 3/9] Create Set-ZertoUserCredential.md --- docs/Set-ZertoUserCredential.md | 88 +++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 docs/Set-ZertoUserCredential.md diff --git a/docs/Set-ZertoUserCredential.md b/docs/Set-ZertoUserCredential.md new file mode 100644 index 0000000..7e0a49f --- /dev/null +++ b/docs/Set-ZertoUserCredential.md @@ -0,0 +1,88 @@ +--- +external help file: ZertoApiWrapper-help.xml +Module Name: ZertoApiWrapper +online version: +schema: 2.0.0 +--- + +# Set-ZertoUserCredential + +## SYNOPSIS + +## SYNTAX + +``` +Set-ZertoUserCredential [-UserCredential] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -UserCredential +PSCredential Object that conatins 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 From b2e5fe7b5cfefdf3d4668b0f10c40d8e9a96621f Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 7 Apr 2020 10:04:55 -0400 Subject: [PATCH 4/9] Update Set-ZertoUserCredential.md --- docs/Set-ZertoUserCredential.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/Set-ZertoUserCredential.md b/docs/Set-ZertoUserCredential.md index 7e0a49f..44ca3c4 100644 --- a/docs/Set-ZertoUserCredential.md +++ b/docs/Set-ZertoUserCredential.md @@ -1,13 +1,14 @@ --- external help file: ZertoApiWrapper-help.xml Module Name: ZertoApiWrapper -online version: +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 @@ -16,21 +17,21 @@ Set-ZertoUserCredential [-UserCredential] [-WhatIf] [-Confirm] [< ``` ## DESCRIPTION -{{Fill in the 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:\> {{ Add example code here }} +PS C:\> Set-ZertoUserCredential -UserCredential $UserCredential ``` -{{ Add example description here }} +Will update the user account used to connect the Zerto Virtual Manager to the the paired Hypervisor. ## PARAMETERS ### -UserCredential -PSCredential Object that conatins the username and password for the updated credentials. +PSCredential Object that contains the username and password for the updated credentials. ```yaml Type: PSCredential @@ -86,3 +87,4 @@ For more information, see about_CommonParameters (http://go.microsoft.com/fwlink ## NOTES ## RELATED LINKS +[PSCredential Object Information](https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.pscredential) From 77fb3c8f678136de5b01aa5799bd1f953c89fed9 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 7 Apr 2020 10:05:31 -0400 Subject: [PATCH 5/9] Fix helpmessage typo --- ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 b/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 index 71495b3..423f02c 100644 --- a/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 +++ b/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 @@ -6,7 +6,7 @@ function Set-ZertoUserCredential { )] param( [Parameter( - HelpMessage = "PSCredential Object that conatins the username and password for the updated credentials.", + HelpMessage = "PSCredential Object that contains the username and password for the updated credentials.", Mandatory )] [pscredential]$UserCredential From a5f3ad4de0b7462720e517c61956e04622971078 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 7 Apr 2020 10:05:34 -0400 Subject: [PATCH 6/9] Update RELEASENOTES.md --- RELEASENOTES.md | 1 + 1 file changed, 1 insertion(+) 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 From e12bf9d85edfa5aacce37aa7de448b84dcb89f9f Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 7 Apr 2020 10:18:37 -0400 Subject: [PATCH 7/9] Fix script level variable --- ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 b/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 index 423f02c..c2e1a9e 100644 --- a/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 +++ b/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 @@ -22,7 +22,7 @@ function Set-ZertoUserCredential { UserName = $UserCredential.UserName Password = $UserCredential.GetNetworkCredential().Password } - if ( $PSCmdlet.ShouldProcess( $script:zertoServer, "Updating hypervisor service account credentials" )) { + if ( $PSCmdlet.ShouldProcess( $script:zvmServer, "Updating hypervisor service account credentials" )) { Invoke-ZertoRestRequest -uri $uri -Method PUT -body ($body | ConvertTo-Json) } } From ad2073f404011081cdbb53ff6c1be736a0e42ed8 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 7 Apr 2020 10:27:22 -0400 Subject: [PATCH 8/9] Fixed submitted body formatting --- ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 b/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 index c2e1a9e..110be91 100644 --- a/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 +++ b/ZertoApiWrapper/Public/Set-ZertoUserCredential.ps1 @@ -19,8 +19,10 @@ function Set-ZertoUserCredential { process { $uri = '/localsite/virtualizationsettings' $body = @{ - UserName = $UserCredential.UserName - Password = $UserCredential.GetNetworkCredential().Password + 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) From 0d6bc39c86d85a08033e9a41913fe413d3fe6a0d Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Tue, 7 Apr 2020 10:30:42 -0400 Subject: [PATCH 9/9] Add an additional example --- docs/Set-ZertoUserCredential.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/Set-ZertoUserCredential.md b/docs/Set-ZertoUserCredential.md index 44ca3c4..9fd7d20 100644 --- a/docs/Set-ZertoUserCredential.md +++ b/docs/Set-ZertoUserCredential.md @@ -28,6 +28,13 @@ 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