job script not working when using variable
hello
i have job script work when sourceparth not variable in copy-item this,
copy-item c:\source "\\$ip\c$" -recurse , when set $sourcepath="c:\$folder", job not start more
#begin script
$folder= read-host "enter source folder name"
$sourcepath="c:\$folder"
$jobs = foreach ($ip in gc c:\cmp.txt) {
start-job -name "copyjob $ip" -argumentlist $ip -scriptblock {
param($ip)
if (test-connection -computername $ip -count 1 -quiet)
{
copy-item $sourcepath "\\$ip\c$" -recurse
}
}
}
$jobs | wait-job
any idea...?
thanks
hi
you have pass $sourcepath in argumentlist, did $ip, same reason : job has own scope, wich different calling scope.
hope helps
Windows Server > Windows PowerShell
Comments
Post a Comment