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

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file