diff --git a/Windows-PowerShell-use-rclone-password-command-for-config-file-password.md b/Windows-PowerShell-use-rclone-password-command-for-config-file-password.md index 29b3e08..0e3ee1d 100644 --- a/Windows-PowerShell-use-rclone-password-command-for-config-file-password.md +++ b/Windows-PowerShell-use-rclone-password-command-for-config-file-password.md @@ -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