Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell -- evaluation of double backslashes

Posted on 2014-10-30
3
Medium Priority
?
176 Views
Last Modified: 2014-10-31
$cp = "\\abcdfs1\$source   \\axyzfs1\$dest  /E /COPY:DAT  /Z /R:5 /W:5 /v /purge /log:$logname1"

I am feeding the above line to a robocopy command, robocopy $cp  

An echo of $cp prints as above, and expands the variables appropriately -- looks great.
When the command executes -  backslashes are stripped from the second segment, such that:
\\axyzfs1\$dest  becomes \axyzfs1\$dest  

I've tried multiple backslashes and still end up with '1'.  Of course, if I use single quotes, the variables don't expand.  I've finagled all my ideas, assistance is definitely required and appreciated.

In a nutshell, I need the "\\" and I have variables to expand.  I can only figure out how to do one or the other.

Thanks.
0
Comment
Question by:apsutechteam
3 Comments
 
LVL 16

Assisted Solution

by:Joshua Grantom
Joshua Grantom earned 1000 total points
ID: 40414945
Your code should look more like this
$source = "\\abcdfs1\myfolder"
$dest = "\\axyzfs1\myfolder"
$logname1 = mylog.log

Invoke-Expression "robocopy $source $dest /E /COPY:DAT /Z /R:5 /W:5 /v /purge /log:$logname1"

Open in new window


I would also edit your topics on the post to include Powershell. :)
0
 
LVL 84

Accepted Solution

by:
David Johnson, CD, MVP earned 1000 total points
ID: 40415032
$source = "abc"
$dest = "def"
$logname1 = "log.txt"
$cp = "\\axyzfs1\$source \\abcdfs1\$dest /E /COPY:DAT  /Z /R:5 /W:5 /v /purge /log:$logname1"
Start-Process robocopy.exe -ArgumentList $cp

Open in new window

0
 

Author Closing Comment

by:apsutechteam
ID: 40415922
Thanks to both of you -- both approaches seem to solve my issue.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question