Score:0

Start-Process argument list includes nested quotes - still possible to do?

au flag

After searching for answers and trying many things, nothing is working.

Goal: Run robocopy from within Powershell in order to grab the latest 30 days of files from a user's home directory, omitting specific folders because speed is important to migrate data off-hours.

Problem: I need to exclude a folder with robocopy with this argument: /XD "application data" However, I can't use normal quotes because the -Argumentlist of Start-Process interprets those as new arguments even without a comma.

Command line robocopy that works fine: robocopy (source) (dest) /S /MAXAGE:30 /XD appsensedata,"application data"

Command I'm working with: Start-Process robocopy -argumentlist "$source","$dest","/R:0","/S","/MAXAGE:30","/XD appsensedata,"application data""

To exclude \application data, Robocopy has to have quotes around the path since it has a space in it. I tried with old 8-character names like \applic~1\ but that didn't work. I also tried double quotes, apostrophe instead of quotes, backslash before each quote...nothing works. The single quotes pass to the robocopy command and don't work because it looks for a folder with the name 'application data' with the single quotes as part of the name.

I just need it to pass those quotes as part of the argument instead of translate it as part of the Start-Process command.

Alternatively, if someone knows of a way to use Copy-Item to take the most recent files recursively and copy them somewhere else recursively, recreating the folder structure. I can not get it to recreate the folder structure, but I probably could with some insanely cumbersome reformatting of the paths.

Also worth nothing that I set up specific NTFS denials on the folders I want to omit, but Robocopy somehow access them still via a mapped drive that is mapped with the account that is denied. If I try to browse with the GUI into those folders, I get denied, but robocopy is able to access it somehow. I REALLY don't understand that part.

Regardless, the real issue is that I can't pass the argument /XD "application data" to robocopy with Powershell. Maybe I should use something other than Start-Process?

I was trying this code first, but it has the same issue with spaces and nested quotes: $options = @("/XD "application data"") @cmdArgs = @("$source","$dest",$options) robocopy @cmdArgs

I'm about ready to just use a looping batch file for my robocopy like the old days, but I feel like there MUST be a way with Powershell. Thanks if you can help me!

Mike Mc. avatar
au flag
I might be okay doing "/XD application*" but some users could have actual folders that get omitted, like "applications for credit" or whatever.
joeqwerty avatar
cv flag
I have to ask, why do you need to do this with Powershell if Robocopy on it's own accomplishes the task?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.