Batch find and replace specific password

Resolved

Batch find and replace specific password

avatar

Hi all,

further to this post

https://forum.devolutions.net/topics/31383/possible-to-search-and-replace-passwords-through-all-sessions

I am in a similar situation where I have many applications with different passwords expiring at different times, and as PowerShell is not my strong suite, I was wondering if you could help me script something to search for password "AAAAAA" and replace it with "BBBBBB" ? (the links in the article don't work or don't seem to lead anywhere)

PS could "Password" be added as an option to the advanced find so then you can batch edit those found entries ?

Thanks in advance !

All Comments (22)

avatar

Hello,

For your information, the PowerShell forum's section is now available here. I have updated the post you have mentioned.

To update passwords using PowerShell, here is a sample script you can use.

$sessions = Get-RDMSession
foreach ($session in $sessions)
{
    $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
    if ($oldpwd -eq "AAAAAAA")
	{
        $newpwd = Convertto-SecureString "BBBBBBB" -AsPlainText -Force
        Set-RDMSessionPassword -Session $session -Password $newpwd
        Set-RDMSession $session -Refresh
    }
}


Let me know if that helps.

Best regards,

Érica Poirier

avatar

Thank you very much Erica ! This has helped greatly.

Note : I was curious why after running the script, if I looked at a modified entry it was still showing the old password, but after I hit F5 to refresh, it was then correctly showing the new, updated password

Also, while running your code (with added user input),

$old_pw = Read-Host -Prompt 'Input your OLD password'
$new_pw = Read-Host -Prompt 'Input your NEW password'
$sessions = Get-RDMSession
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
    }
}


I did see these errors:

Get-RDMSessionPassword : Object reference not set to an instance of an object.
At C:\Program Files\Devolutions\Remote Desktop Manager\RDM_Update_Specific_Password.ps1:6 char:15
+     $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-RDMSessionPassword], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,RemoteDesktopManager.PowerShellModule.GetRDMSessionPasswordCommand



Would these be for entries with no passwords ?

avatar

Hello,

Thank you for your feedback.

About the error message, what RDM version and RDM PowerShell module version are you using?

Do you know what entry type is throwing this error message?

Best regards,

Érica Poirier

avatar

Hi Erica

I actually get pages and pages of this same error, so not sure what entry or entry type it is (I have a mix of RDP and SSH)

RDM = 2022.3.29.0 64-bit
PS module = (can't see full version number)

PS C:\Program Files\Devolutions\Remote Desktop Manager> Get-InstalledModule

Version    Name                                Repository           Description
-------    ----                                ----------           -----------
2021.2.... RemoteDesktopManager                PSGallery            Devolutions Remote Desktop Manager (RDM) PowerShell Module
avatar

Hello,

Since you are using the latest version of RDM, you would need to update the RDM PowerShell module to the latest version as well (or at least 2022.3.x). Run the following to update it, and then reopen the PowerShell window:

Update-Module RemoteDesktopManager


You can try to use the script again after.

Best regards,

Richard Boisvert

avatar

Updated, but the error still occurs. However it still correctly updates the required entry

Resize PowerShell buffer and window size
Exception setting "BufferSize": "Cannot set the buffer size because the size specified is too large or too small.
Parameter name: value                                                                                                                                                                                              Actual value was 192,4000."                                                                                                                                                                                        At line:3 char:1                                                                                                                                                                                                   + $Host.UI.RawUI.BufferSize = new-object System.Management.Automation.H ...                                                                                                                                        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting

Loading RDM CmdLet (Module)
PS C:\Program Files\Devolutions\Remote Desktop Manager>
PS C:\Program Files\Devolutions\Remote Desktop Manager> Get-InstalledModule

Version    Name                                Repository           Description
-------    ----                                ----------           -----------
2022.3.1.2 RemoteDesktopManager                PSGallery            Devolutions Remote Desktop Manager (RDM) PowerShell Module


PS C:\Program Files\Devolutions\Remote Desktop Manager> $old_pw = Read-Host -Prompt 'Input your OLD password'
Input your OLD password: AAAAAA
PS C:\Program Files\Devolutions\Remote Desktop Manager> $new_pw = Read-Host -Prompt 'Input your NEW password'
Input your NEW password: BBBBBB
PS C:\Program Files\Devolutions\Remote Desktop Manager> $sessions = Get-RDMSession
PS C:\Program Files\Devolutions\Remote Desktop Manager> 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
>>     }
>> }
Get-RDMSessionPassword : Object reference not set to an instance of an object.
At line:3 char:15
+     $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-RDMSessionPassword], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,RemoteDesktopManager.PowerShellModule.GetRDMSessionPasswordCommand


avatar

Hello,

Thank you for your feedback.

Could you please try this foreach loop and let me know what entry type is triggering these errors?

foreach ($session in $sessions)
{
    Write-Host $session.Name
    Write-Host $session.ConnectionType
    $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
    PAUSE

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


Best regards,

Érica Poirier

avatar

Hi Erica,

seems to be a mix of SSHConfigured and RDPConfigured. Mote I have > 1000 entries so I had to remove the PAUSE and I stopped it after this chunk of messages
SCRIPT:

$old_pw = Read-Host -Prompt 'Input your OLD password'
$new_pw = Read-Host -Prompt 'Input your NEW password'
$sessions = Get-RDMSession
foreach ($session in $sessions)
{
    Write-Host $session.Name
    Write-Host $session.ConnectionType
    $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
    PAUSE

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


OUTPUT:

.
.

Group
test_template.rdp
RDPConfigured
Get-RDMSessionPassword : Object reference not set to an instance of an object.
At line:5 char:15
+     $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-RDMSessionPassword], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,RemoteDesktopManager.PowerShellModule.GetRDMSessionPasswordCommand

.
.
.
* BT RDP Sessions
Group
AMS
Group
sshbastion1.kmg.ams.local (SSH Bastion)
SSHShell
Get-RDMSessionPassword : Object reference not set to an instance of an object.
At line:5 char:15
+     $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-RDMSessionPassword], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,RemoteDesktopManager.PowerShellModule.GetRDMSessionPasswordCommand

Apps
Group
BI
Group
twibidb01vth
RDPConfigured
Get-RDMSessionPassword : Object reference not set to an instance of an object.
At line:5 char:15
+     $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-RDMSessionPassword], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,RemoteDesktopManager.PowerShellModule.GetRDMSessionPasswordCommand

Citrix
Group
TWPCTXSVR050VTH
RDPConfigured
Get-RDMSessionPassword : Object reference not set to an instance of an object.
At line:5 char:15
+     $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-RDMSessionPassword], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,RemoteDesktopManager.PowerShellModule.GetRDMSessionPasswordCommand

TWTCTXSVR010VTH
RDPConfigured
Get-RDMSessionPassword : Object reference not set to an instance of an object.
At line:5 char:15
+     $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-RDMSessionPassword], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,RemoteDesktopManager.PowerShellModule.GetRDMSessionPasswordCommand

CMS
Group
twpcmsapp02vcl
RDPConfigured
Get-RDMSessionPassword : Object reference not set to an instance of an object.
At line:5 char:15
+     $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-RDMSessionPassword], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,RemoteDesktopManager.PowerShellModule.GetRDMSessionPasswordCommand

DCM
Group
twpdcm6vto
RDPConfigured
Get-RDMSessionPassword : Object reference not set to an instance of an object.
At line:5 char:15
+     $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-RDMSessionPassword], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,RemoteDesktopManager.PowerShellModule.GetRDMSessionPasswordCommand

EKB
Group
twppekb02v
RDPConfigured
Get-RDMSessionPassword : Object reference not set to an instance of an object.
At line:5 char:15
+     $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-RDMSessionPassword], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,RemoteDesktopManager.PowerShellModule.GetRDMSessionPasswordCommand

twpvekb01v
RDPConfigured
Get-RDMSessionPassword : Object reference not set to an instance of an object.
At line:5 char:15
+     $oldpwd = Get-RDMSessionPassword -Session $session -AsPlainText
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-RDMSessionPassword], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,RemoteDesktopManager.PowerShellModule.GetRDMSessionPasswordCommand


avatar

Hello,

Thank you for your feedback.

That's quite strange as it should pull out the password without any problem.

How the credentials are set for these entries? Are they saved in the entry, bind to a credential entry in the same vault, bind to a user vault entry or have a user specific setting?

Best regards,

Érica Poirier

avatar

Hi Erica,

FYI "twpvekb01v" (the second last one in the list) is an embedded RDP file

It does update the correct entry's password from "old" to "new", just that it produces these errors, so no big deal (I can ignore them)

Screenshot of the properties of "twppekb02v" (the last one from the output above):

forum image

avatar

Hello,

Can you confirm what type of data source you are using? It should now be throwing that error.

As a test, could you also try to use PowerShell 7.2 or 7.3 and verify if the issue still occurs? File > Options > Types > Others > PowerShell version = PowerShell 7
forum image


Best regards,

Richard Boisvert

avatar

Hi Richard,

The data source is a "local data source" (a *.db file on my filesystem)

The PowerShell version was set to "Default".
When I changed it to PowerShell 7 (as advised), it ran cleanly without any errors !

Thank so much for the solution !

avatar

Hello,

Glad it is working with PowerShell 7!

As a side note, in the next major release, 2023.1, PowerShell 5.1 will be deprecated, and you will need to use PS 7 instead.

Best regards,

Richard Boisvert

avatar

Hi Devolutions team,

I'm trying to use the above PS script to update my password but when it runs, it seems to have troubles connecting to Devolutions Cloud

It opens a browser and asks to enter my Devolutions Cloud credentials (which I do). It accepts them and says the tab can be closed, however when it goes back to the PowerShell screen it just stays on "Connecting to Devolutions Cloud":

forum image

Is there a way to stop it trying to connect to Cloud ?

avatar

Hello,

After you run the $sessions = Get-RDMSession , could you do $sessions.count and make sure it returns a number > 0?

Could you also confirm what version of RDM you are using, and the version of the RDM PS module (Get-RDMInstance)?

Best regards,

Richard Boisvert

avatar

Hi Richard,

as requested
a) it returns 0
b) see below

I ran it again today to get you the details and in teh first run, it didn't try to connect to the cloud (the ZZZZZZZZZ password was most likely not found). As a result, it completed successfully without the above issue. I then ran it again with 2 test accounts that had EEEEE as the password and the issue occurred again

forum image

avatar

FYI, the code is:

$old_pw = Read-Host -Prompt 'Input your OLD password'
$new_pw = Read-Host -Prompt 'Input your NEW password'
$sessions = Get-RDMSession
$session.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
    }
}
avatar

also
RDM v 2022.3.35.0 64-bit
using Powershell 7 setting

avatar

Hello,

Could you try with the latest version of the PowerShell module (2022.3.1.5) : https://www.powershellgallery.com/packages/remotedesktopmanager ?

I just tried it on my end, and it works correctly:
forum image

Best regards,

Richard Boisvert

avatar

Still no go

Seems to run first time without connecting to cloud, but if I rerun it, it attempts to connect (opens EDGE browser tab, successfully connects, closes tab)
forum image

However even though it reports 0 and tries connecting to cloud, it does seem to complete successfully, which is better than what it was doing previously

avatar

Hello,

I had made a typo in the cmdlet I initially asked you to run, if you run $sessions.count (I missed the s at the end of session), it will return a number greater than zero.

Since your passwords were modified, you should be all set!

Best regards,

Richard Boisvert

avatar

Hi Richard, no problem. I updated the command and now it shows the correct number of sessions