Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Robocopy - adding variable in Start-Job Scriptblock

$
0
0

Hello,

Im writing a little robocopy gui and my problem is, that I cannot pass the variable for the logging to my Job.

Source, target, Options are processed well, but only the logging is not.

I know how to pass variables to Scripblocks with params and Argumentlists or with using but only one variable does not work.

I tried so much, but got no idea left..

The invoke-expression works as long as i do not pass the /log:somepath to it, but I have to, and it has to be a variable..

Thanks for helping in advance..

Here is a part of the Code..
--snip--
$timestamp=get-date-uformat"%Y-%m%-%d"
$Source=$txtSource.Text
$Target=$txtTarget.Text
$job=$txtJob.Text
$log="/LOG+:$LogPath\$timestamp-$Job.log"
$What="/MIR /COPY:DAT"
# $options = "/E /NC /NS /NP /R:1 /W:5 /MT /Z /LOG:Robocopy.log" # FUNKTIONIERT
$options="/E /NC /NS /NP /R:1 /W:5 /MT /Z "
$rtbcommand.Text =""
$rtbcommand.AppendText("Robo-sync is copying files...`r`n"
)
$ScriptBlock={
param(
$timestamp,$Source,$Target,$Options,$What,$Job,$Script:LogPath,$Log)
#$xcmd = @("`"$Source`"", "`"$Target`"", "$what", "$options")
#Robocopy "`"$Source`"" "`"$Target`"" /MIR /COPY:DAT /R:1 /W:1
Invoke-Expression"Robocopy $Source$Target$What$options" # this only works without logfile, or with fixed one
}
$job=Start-Job-Name'RoboSync'-ScriptBlock$Scriptblock-ArgumentList$timestamp, $Source, $Target, $options, $What, $job, $Log,$Script:LogPath
--snap

(Please visit the site to view this media)


Viewing all articles
Browse latest Browse all 6937

Trending Articles