Search code examples
c#visual-studiopowershellprocessstartinfo

Can't pass through "" to powershell using ProcessStartInfo arguments, C#


I'm unable to pass through an argument to powershell which contains "". When I use the equivalent code but change the application to cmd the "" are able to pass through.

The argument I'd like powershell to execute is:

Copy-Item -Path "{Working Directory}\W11F-assets\" -Destination "C:\\Windows\W11F-assets" -Recurse

This is the code that's calling that function:

    ProcessStartInfo movefile = new ProcessStartInfo("powershell.exe");
    string flocation = Directory.GetCurrentDirectory();
    movefile.UseShellExecute = true;
    movefile.Arguments = "Copy-Item -Path \"" + flocation + "\\W11F-assets\" -Destination \"C:\\Windows\\W11F-assets\" -Recurse";
    Process.Start(movefile);

Solution

  • Was able to solve issue by replacing \" with '.