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!