Updated Windows PowerShell use rclone password command for config file password (markdown)

albertony 2020-05-03 13:53:10 +02:00
parent b2d26c97dd
commit 4e41e60620

@ -52,13 +52,13 @@ if (-not (Test-Path -LiteralPath 'C:\Path\To\Password.sec'))
New-Object -TypeName System.Net.NetworkCredential -ArgumentList '', (Get-Content -LiteralPath 'C:\Path\To\Password.sec' -Raw | ConvertTo-SecureString) | Select-Object -ExpandProperty Password
```
It can be condensed into a single-liner that can be supplied as command line argument to rclone, i.e. from a script (but definitely not convenient having to enter interactively):
It can be condensed into a single-liner that can be supplied directly as command-line argument powershell.exe:
```
rclone lsd remote: --password-command "powershell -NoProfile -Command [Console]::OutputEncoding = [Text.Encoding]::UTF8; if (-not (Test-Path -LiteralPath 'C:\Path\To\Password.sec')) { Read-Host -Prompt 'Enter rclone configuration password' -AsSecureString | ConvertFrom-SecureString | Out-File -LiteralPath 'C:\Path\To\Password.sec' -NoNewline } New-Object -TypeName System.Net.NetworkCredential -ArgumentList '', (Get-Content -LiteralPath 'C:\Path\To\Password.sec' -Raw | ConvertTo-SecureString) | Select-Object -ExpandProperty Password"
powershell -NoProfile -Command [Console]::OutputEncoding = [Text.Encoding]::UTF8; if (-not (Test-Path -LiteralPath 'C:\Path\To\Password.sec')) { Read-Host -Prompt 'Enter rclone configuration password' -AsSecureString | ConvertFrom-SecureString | Out-File -LiteralPath 'C:\Path\To\Password.sec' -NoNewline } New-Object -TypeName System.Net.NetworkCredential -ArgumentList '', (Get-Content -LiteralPath 'C:\Path\To\Password.sec' -Raw | ConvertTo-SecureString) | Select-Object -ExpandProperty Password
```
To make sure the command is automatically included in your every rclone commands you can store it in environment variable `RCLONE_PASSWORD_COMMAND` instead:
To make sure the command is automatically executed for every rclone command, you can now just store this entire string as the value of environment variable `RCLONE_PASSWORD_COMMAND`. You can also supply it to rclone command-line argument --password-command with double quotes around it: `rclone lsd remote: --password-command "powershell -NoProfile -Command [Console]::OutputEncoding ..."`. If you want to set the environment variable from command prompt or a batch script remember to escape the `|'`characters into `^|`, like this:
```
SET RCLONE_PASSWORD_COMMAND=powershell -NoProfile -Command [Console]::OutputEncoding = [Text.Encoding]::UTF8; if (-not (Test-Path -LiteralPath 'C:\Path\To\Password.sec')) { Read-Host -Prompt 'Enter rclone configuration password' -AsSecureString ^| ConvertFrom-SecureString ^| Out-File -LiteralPath 'C:\Path\To\Password.sec' -NoNewline } New-Object -TypeName System.Net.NetworkCredential -ArgumentList '', (Get-Content -LiteralPath 'C:\Path\To\Password.sec' -Raw ^| ConvertTo-SecureString) ^| Select-Object -ExpandProperty Password