Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell -- evaluation of double backslashes

Posted on 2014-10-30
3
Medium Priority
?
161 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 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 83

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
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 …
Progress

688 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