Powershell string parsing on JSON blob flags

Hey !

I wasn't sure whether that was better located in HOW TOs or here, since I'm just reporting a solution for a problem which has none documented, but is probably not worth a guide.

What is the problem you were having with rclone?

  • Running in powershell 5.1
  • latest current version of rclone

Same problem reported in the topic named Google Drive Service Account Blob

When trying to give rclone the GCP service account credentials in a JSON blob (as a string) via the --drive-service-account-credentials flag, it fails, giving
Command ls needs 1 arguments maximum: you provided 5 non flag arguments: ["mydrive:" "PRIVATE" "KEY-----\\nxxx\\n-----END" "PRIVATE" "KEY-----\\n,\n client_email: xx@xxiam.gserviceaccount.com,\n client_id: 107054507531889133420,\n auth_uri: https://accounts.google.com/o/oauth2/auth,\n token_uri: https://oauth2.googleapis.com/token,\n auth_provider_x509_cert_url: https://www.googleapis.com/oauth2/v1/certs,\n client_x509_cert_url: https://www.googleapis.com/robot/v1/metadata/x509/xxx.iam.gserviceaccount.com\n}\n"]

This is, as pointed out by @ncw, a powershell parsing issue. As stated in the link topic, a workaround is in any case to set the string in an environment variable, which works well.

However, should you want to provide the string in the command line, I've found a way to do that via powershell by doing the following :
./rclone.exe your-command "mydrive:" --drive-service-account-credentials ($myjsonblob.Replace('"', '\"'))
Using the string method replace to escape the quotes inside works. For some reason, however, it doesn't work when giving the argument via the "=" notation, they have to be space separated. I didn't investigate as to why, as spending hours trying to solve a parsing issue is enough for one day :slight_smile:

What is your rclone version (output from rclone version)


Which OS you are using and how many bits (eg Windows 7, 64 bit)

Windows 10 64 bits
Powershell 5.1

The command you were trying to run (eg rclone copy /tmp remote:tmp)

./rclone.exe --config "rclone.conf" ls "mydrive:" --drive-service-account-credentials="$myvar"

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