Solved

Powershell -- evaluation of double backslashes

Posted on 2014-10-30
3
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Assisted Solution

by:Joshua Grantom
Joshua Grantom earned 250 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 81

Accepted Solution

by:
David Johnson, CD, MVP earned 250 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

710 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