Skip to content

Commit b4c5673

Browse files
committed
Added new cmdlet for updating a root account password
1 parent f666e62 commit b4c5673

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

src/StorageGRID-Webscale.psm1

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@ function Global:Update-SGWSwiftAdminPassword {
610610
if (!$Server) {
611611
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
612612
}
613+
if ($Server.APIVersion -gt 1) {
614+
Write-Error "This Cmdlet is only supported with API Version 1.0. Use the new Update-SGWPassword Cmdlet instead!"
615+
}
613616
}
614617

615618
Process {
@@ -637,6 +640,73 @@ function Global:Update-SGWSwiftAdminPassword {
637640
}
638641
}
639642

643+
<#
644+
.SYNOPSIS
645+
Changes the root user password for the Storage Tenant Account
646+
.DESCRIPTION
647+
Changes the root user password for the Storage Tenant Account
648+
#>
649+
function Global:Update-SGWPassword {
650+
[CmdletBinding()]
651+
652+
PARAM (
653+
[parameter(
654+
Mandatory=$True,
655+
Position=0,
656+
HelpMessage="ID of a StorageGRID Webscale Account to update.",
657+
ValueFromPipeline=$True,
658+
ValueFromPipelineByPropertyName=$True)][String[]]$Id,
659+
[parameter(
660+
Mandatory=$True,
661+
Position=1,
662+
HelpMessage="Old Password.")][String]$OldPassword,
663+
[parameter(
664+
Mandatory=$True,
665+
Position=2,
666+
HelpMessage="New Password.")][String]$NewPassword,
667+
[parameter(
668+
Mandatory=$False,
669+
Position=3,
670+
HelpMessage="StorageGRID Webscale Management Server object. If not specified, global CurrentSGWServer object will be used.")][PSCustomObject]$Server
671+
)
672+
673+
Begin {
674+
if (!$Server) {
675+
$Server = $Global:CurrentSGWServer
676+
}
677+
if (!$Server) {
678+
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
679+
}
680+
if ($Server.APIVersion -lt 2) {
681+
Write-Error "This Cmdlet is only supported with API Version 2.0 and later. Use the old Update-SGWSwiftAdminPassword Cmdlet instead!"
682+
}
683+
}
684+
685+
Process {
686+
$Id = @($Id)
687+
foreach ($Id in $Id) {
688+
$Uri = $Server.BaseURI + "/grid/accounts/$id/change-password"
689+
$Method = "POST"
690+
691+
$Body = @"
692+
{
693+
"password": "$NewPassword",
694+
"currentPassword": "$OldPassword"
695+
}
696+
"@
697+
try {
698+
$Result = Invoke-RestMethod -WebSession $Server.Session -Method $Method -Uri $Uri -Headers $Server.Headers -Body $Body -ContentType "application/json"
699+
}
700+
catch {
701+
$ResponseBody = ParseExceptionBody $_.Exception.Response
702+
Write-Error "$Method to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
703+
}
704+
705+
Write-Output $Result.data
706+
}
707+
}
708+
}
709+
640710
<#
641711
.SYNOPSIS
642712
Retrieve StorageGRID Webscale Account Usage Report

0 commit comments

Comments
 (0)