It might be only part of the Anwser, but for CMD the escape character for | is ^, if use ^| then the output is different but not correct yet (i did change the code somewhat to make it work so you might want to copy and adjust mine), Ruby might use the same or something different i am not sure but i believe youre on the right track.
powershell.exe -command {invoke-command -scriptblock {$oldpath = "C:\Users\...\corehr"; $newpath = "C:\Users\...\corehr\07241439"; Get-ChildItem -Path $oldpath -Recurse | where {($_.FullName -notmatch $oldpath.replace('\','\\')) -or ($_.FullName -notmatch $newpath.replace('\','\\'))}}}
With CMD Results in
INFO: Could not find files for the given pattern(s).
But it in powershell it gave:
Directory: C:\Users\...\corehr
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 24-7-2017 15:41 test1
d---- 24-7-2017 15:41 test2
Replacing | with ^| results in
invoke-command -scriptblock {$oldpath = C:\Users\...\corehr; $newpath = C:
\Users\...\corehr\07241439; Get-ChildItem -Path $oldpath -Recurse | where
{($_.FullName -notmatch $oldpath.replace('\','\\')) -or ($_.FullName -notmatch
$newpath.replace('\','\\'))}}
Now it thinks the -command input is a string? but as you can see, the pipe character is correctly displayed in this output.
I hope that the above information will be helpful for you.