Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Robocopy powershell script with changing source.

$
0
0

I have to move a large amount of backups from one storage to another during off hours. I have written a script to move the files no problem but I want to improve it by making the source point at a text file where I can input the new source address daily so I don't have to get into the script everyday instead. Here is my current script.

$source = "\\IP\phdvb_flr_cifs\disk-2\partition-1\Site\Share" 
$destination = "\\IP\Archive\7-12-2018\1"
$source2 = "\\IP\phdvb_flr_cifs\disk-2\partition-1\Site\Users" 
$destination2 = "\\IP\Archive\7-12-2018\2" 
$date = get-date -format M.d.yyyy 
$logFile = "robocopy.log" 
$logName = $date+$logFile 
$LogDir = "\\IP\Archive\7-12-2018\"


New-Item -Type File -Name $logName -Path $logDir -Force  
 
ROBOCOPY $source $destination /s /COPYALL /Z /R:5 /W:30 /NFL /NDL /NP /XJ | /LOG:file $logDir\$logName
ROBOCOPY $source2 $destination2 /s /COPYALL /Z /R:5 /W:30 /NFL /NDL /NP /XJ | /LOG+:file $logDir\$logName

I was going to replace the source with:

$source = get-content -path \\IP\c$\winnt\scripts\Test.txt

but when testing this and trying to print source it would show me an error like:

Can't find file This is just a test.

"This is just a test." is the contents of the file. Do you know why it is telling me it can't find the file before printing the contents or is there a better way to go about something like this?


_Sam_


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>