Scripting via PowerShell, newbie questions

Advertisement

JamesEdmondsUKPN
Joined:
Posts:
3
Location:
England

Scripting via PowerShell, newbie questions

Hello,

I am writing a PowerShell script to try and automate some file transfers we do via SCP.
I am trying to run the below:
& 'C:\Program Files (x86)\WinSCP\WinSCP.exe' /log="C:\Users\username\WinSCP.log" scp://username:password@hostname /command 'put ""C:\Users\username\OneDrive - CompanyName\Documents\Scripts\PowerShell\Certificates\hostname\hostname-pfxpassword.txt"" /users/home/username/' "exit"

I'm really struggling with the syntax for the file path with spaces in. No spaces in the path works fine, but if I use single, double or double double quotes around the path, I just get errors like this in the log file:
. 2023-02-08 10:46:44.495 File: "\\C:\Users\username\OneDrive"
* 2023-02-08 10:46:44.496 (EOSError) System Error.  Code: 123.
 
* 2023-02-08 10:46:44.496 The filename, directory name, or volume label syntax is incorrect
. 2023-02-08 10:46:44.496 Asking user:
. 2023-02-08 10:46:44.496 File or folder '\\C:\Users\username\OneDrive' does not exist. ("System Error.  Code: 123.
 
. 2023-02-08 10:46:44.496 The filename, directory name, or volume label syntax is incorrect")
< 2023-02-08 10:46:44.496 Script: File or folder '\\C:\Users\username\OneDrive' does not exist.
< 2023-02-08 10:46:44.496 Script: System Error.  Code: 123.
 
< 2023-02-08 10:46:44.496 The filename, directory name, or volume label syntax is incorrect
. 2023-02-08 10:46:44.496 Answer: Abort

When running in PowerShell in this way, how can I correct the syntax to accommodate spaces in the file path?

Additionally, should I be looking to use the .NET assembly instead, and would it help with this kind of automation?

Cheers
James

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum