Solved

Powershell -- evaluation of double backslashes

Posted on 2014-10-30
3
147 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 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 78

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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.
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 …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now