The configuration password cannot be read

AFTER I UPGRADED POWERSHELL TO V7.3, PROMPT:Failed to load config file "C:\Users\User\.config\rclone\rclone.conf": password-command returned empty string,Previously it was possible to pass RCLONE_PASSWORD_COMMAND,
Is there anyone who can help me, thank you

What is your RCLONE_PASSWORD_COMMAND set to then?

Variable name: RCLONE_PASSWORD_COMMAND, variable value: powershell D:\rcpw\rcpw.ps1,In the rcpw.ps1 file, Read-Host -Prompt 'Enter rclone configuration password' -AsSecureString | ConvertFrom-SecureString | Out-File -FilePath D:\rcpw\rcpw.txt,This configuration worked fine in versions prior to PowerShell 7.3, and problems occurred after upgrading to V7.3

That command you posted only writes to a file, ... | Out-File -FilePath D:\rcpw\rcpw.txt, and would not work regardless of PowerShell version. I assume you missed some of the contant of the D:\rcpw\rcpw.ps1 file?

Looks like you took inspiration from this thread:

1 Like

... or copied rcpw.txt from another pc or user.

The encrypted password stored in rcpw.txt can only be successfully decrypted by the Windows user and pc used to encrypt it.

If you move to another Windows user or pc then you will have to create a new rcpw.txt file by following the instructions from the beginning. I suggest you rename the old file to something like rcpw.txt.bak first.

1 Like

Thank you for the explanation, but my usage environment has not changed, just powershell upgraded to V7.3, I rolled powershell back to V7.2, and then it works normally, so I thought it was a problem with the powershell version.

I just tested my password command and worked fine in PowerShell 7.3 (installed using winget), so I don't think your issue is (directly) related to PowerShell 7.3

Do you see your password if executing the below command in PS 7.2 and 7.3?

(New-Object -TypeName PSCredential -ArgumentList @( 'user', ((Get-Content -Path D:\rcpw\rcpw.txt) | ConvertTo-SecureString))).GetNetworkCredential().Password

What is the output from this command:

cat D:\rcpw\rcpw.ps1

Please mark the output as "Preformatted text", you can find it in the forum editor menu

Thank you very much, but I found strange issues, as follows:
1.Run PowerShell
2.Run 'rclone --password-command "powershell D:\rcpw\rcpw.ps1" lsd b2:'
output:Failed to load config file "C:\Users\User\.config\rclone\rclone.conf": password-command returned empty string
3.Then run:powershell
4.Then run it again: rclone --password-command "powershell D:\rcpw\rcpw.ps1" lsd b2:
5.Right now:PS C:\Windows\System32> rclone --password-command "powershell D:\rcpw\rcpw.ps1" lsd b2:
-1 2022-11-14 14:04:55 -1 my-bak
now OK
must first run :powershell and the password command will run correctlyThis is confusing,And causes the script that is scheduled to run to not run correctly

OK, let's take it step by step, first I need to better understand your situation.

Do you see your password if executing the below command?

(New-Object -TypeName PSCredential -ArgumentList @( 'user', ((Get-Content -Path D:\rcpw\rcpw.txt) | ConvertTo-SecureString))).GetNetworkCredential().Password

What is the output from this command:

cat D:\rcpw\rcpw.ps1

Please mark the output as "Preformatted text", you can find it in the forum editor menu

well,yes,I can see the password when this command is executed,and cat D:\rcpw\rcpw.ps1 output:

 cat D:\rcpw\rcpw.ps1
(New-Object -TypeName PSCredential -ArgumentList @( 'user', ((Get-Content -Path D:\rcpw\rcpw.txt) | ConvertTo-SecureString))).GetNetworkCredential().Password
PS D:\>

Perfect, now try if this shows your password:

pwsh  D:\rcpw\rcpw.ps1

If it does, then try this

rclone --password-command "pwsh D:\rcpw\rcpw.ps1" lsd b2:
1 Like

That's great,It can be executed successfully

 rclone --password-command "pwsh D:\rcpw\rcpw.ps1" lsd b2:
          -1 2022-11-16 14:07:34        -1 my-bak

Happy to hear!

I hope it also solved your issue with the scheduled script, otherwise please share the (relevant part of the) script and the error you see.

@albertony I tried without success to find a solution that would work in both Windows PowerShell (5.1) and PowerShell 7, do you have any ideas?

What is the situation, exactly? Is it: The original method from that old thread still works, as is, but not in PowerShell 7 if you use --password-command "powershell ...", you have to change it to "pwsh ..."?

The issue is that this command doesn't work in PowerShell 7 (pwsh):

.\rclone.exe config show --password-command "powershell ./configpw.ps1"
2022/11/16 08:54:53 Failed to load config file "...": password-command returned empty string

I would expect it to execute configpw.ps1 using my Windows PowerShell (5.1), but it obviously doesn't work as expected. Executing just "powershell ./configpw.ps1" in the PowerShell 7 prompt works fine, but seems to use PowerShell 7. If I type powershell in the Start Menu then I get the Windows PowerShell 5.1...

My question is: How can I write the above command generically to make it execute correctly in Task Scheduler, CMD, Windows PowerShell (5.1) and PowerShell 7 (if installed)?

Ok, thanks for the details. I reproduced it myself now. When using powershell in password command from a pwsh shell, and adding *> out.txt to the end of the password-command I see in the produced out.txt file that it errors out with:

ConvertTo-SecureString : The 'ConvertTo-SecureString' command was found in the module 'Microsoft.PowerShell.Security',
but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Security'.

The problem seems to be that when running from pwsh (PowerShell 7) it prepends PS7 installation's module path into $Env:PSModulePath, and this gets inherited by rclone, and then by the powershell command it executes as password command. Now that powershell (Windows PowerShell 5.1) command finds the Microsoft.PowerShell.Security module for PowerShell 7 instead of the Windows PowerShell 5.1 one, and are not able to use it.

To work around this, one possibility is to, before starting powershell in the password command, clear any PSModulePath variable (which should be set if and only if inherited from a powershell/pwsh "parent" shell rclone is running from). This will ensure that when powershell is run it sets its own proper default PSModulePath value.

.\rclone.exe config show --password-command "cmd /c SET PSModulePath=&powershell ./configpw.ps1"

Thats a quick and dirty fix, off the top of my head. Maybe we can come with up with a better..?

So yes, good question, what is the good, general solution for this... :thinking:

1 Like

Another alternative is to keep the existing password command, e.g.

.\rclone.exe config show --password-command "powershell ./configpw.ps1"

But modify the script (here: configpw.ps1), and add a statement to the top that ensures PSModulePath is correct in any case. E.g.:

$Env:PSModulePath = [System.Environment]::GetEnvironmentVariable("PSModulePath","Machine")

Still just a workaround, though. It may or may not be better than the previous one..

Since I'm only using V7, the problem seems to be solved, thanks for your patience and help.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.