Using Powershell to change passwords?

Using Powershell to change passwords?

avatar

We have several folders of servers that have usernames but all have the same password. The servers in each folder use inherited credentials. Currently, when we change passwords, I have to go to each individual folder, go to properties and update the password. I'm wondering if this could be done with a powershell command after selecting ALL of the folders, or perhaps a parent folder above them all? If so, can you give an example of the powershell command?

Thanks,
Brad

All Comments (3)

avatar

Hello Brad,

You could use the following PowerShell script. It will prompt you to enter the old and new password and replace entries with the old password with the new one. It assumes you only wish to change it in one vault.

#check if RDM PS module is installed
if(-not (Get-Module Devolutions.PowerShell -ListAvailable)){
    Install-Module Devolutions.PowerShell -Scope CurrentUser
}

# Adapt the data source name
$ds = Get-RDMDataSource -Name "NameOfYourDataSourceHere"
Set-RDMCurrentDataSource $ds

$vault = Get-RDMVault -Name "VaultName"
Set-RDMCurrentRepository $vault

$old_pw = Read-Host -Prompt 'Input your OLD password'
$new_pw = Read-Host -Prompt 'Input your NEW password'
$sessions = Get-RDMSession
#$sessions.count

foreach ($session in $sessions)
{
    $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText

    if ($oldpwd -eq $old_pw)
	{
        $newpwd = Convertto-SecureString $new_pw -AsPlainText -Force
        Set-RDMSessionPassword -Session $session -Password $newpwd
        Set-RDMSession $session -Refresh
    }
}


Best regards,

Richard Boisvert

avatar

I think I'm missing something. If I select the parent folder that I want all passwords within it to change, and then go to powershell and paste in the script above, the program just spins and nothing happens. What step am I missing?

avatar

Hello Brad,

The script I provided would change it for all the entries in a vault that matches the old password; if you want to limit it to a particular group, you would need to change the line

$sessions = Get-RDMSession

with the following:

$session = Get-RDMSession | Where-Object {$_.group -like "group-name*"}


Best regards,

Richard Boisvert