diff --git a/module/PowerNSX.psm1 b/module/PowerNSX.psm1 index 8a929672..02a4a80e 100644 --- a/module/PowerNSX.psm1 +++ b/module/PowerNSX.psm1 @@ -13841,10 +13841,14 @@ function Set-NsxEdge { #cliSettings if ( $PsBoundParameters.ContainsKey('userName') ) { - if ( invoke-xpathquery -node $_Edge -querymethod SelectSingleNode -Query "child::cliSettings/userName" ) { - $_Edge.cliSettings.username = $userName + if ( $PsBoundParameters.ContainsKey('password') ) { + if ( invoke-xpathquery -node $_Edge -querymethod SelectSingleNode -Query "child::cliSettings/userName" ) { + $_Edge.cliSettings.username = $userName + } else { + Add-XmlElement -xmlroot $_Edge.cliSettings -xmlElementName "userName" -xmlElementText $userName + } } else { - Add-XmlElement -xmlroot $_Edge.cliSettings -xmlElementName "userName" -xmlElementText $userName + throw "You need to specify a password for change username..." } } diff --git a/tests/integration/04.Edge.Tests.ps1 b/tests/integration/04.Edge.Tests.ps1 index 9f89ef91..d6deafb6 100644 --- a/tests/integration/04.Edge.Tests.ps1 +++ b/tests/integration/04.Edge.Tests.ps1 @@ -734,10 +734,12 @@ Describe "Edge" { $edge.cliSettings.remoteAccess | should be "true" } - it "Change (SSH) username via Set-NsxEdge" { - Get-NsxEdge $name | Set-NsxEdge -userName powernsxviasetnsxedge -confirm:$false + it "Change (SSH) username (and Password) via Set-NsxEdge" { + #it is mandatory to change username (and Password) on the same time (bug or feature ?) + Get-NsxEdge $name | Set-NsxEdge -userName powernsxviasetnsxedge -Password "Vmware1!Vmware1!" -confirm:$false $edge = Get-NsxEdge $name $edge.cliSettings.userName | should be "powernsxviasetnsxedge" + #It is impossible to check if the password is modified... } it "Change Password Expiry via Set-NsxEdge" { @@ -751,11 +753,6 @@ Describe "Edge" { $edge = Get-NsxEdge $name $edge.cliSettings.sshLoginBannerText | should be "Secured by Set-NsxEdge" } - - it "Change Password via Set-NsxEdge" { - Get-NsxEdge $name | Set-NsxEdge -Password "Vmware1!Vmware1!" -confirm:$false - #There is no really check if the value is changed... - } } Context "Misc" {