Solved

Powershell -- evaluation of double backslashes

Posted on 2014-10-30
3
150 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 79

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
firstswap challenge 20 77
why my code login on a web site with access vba don't work on microsoft access 2016 26 65
Programatically extract date from website 8 77
Query Syntax 17 34
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.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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…

773 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