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

Remote Scheduling of a job

$
0
0

Hi,

I have to schedule a task to run a batch file on remote machines which will  launch a Python test script to launch a GUI app and automate the functionality of it(to be exact, it's a Sikuli script run via Jython script runner). I'm using schtasks to schedule the same and it works fine on Windows 7 machines but on Windows XP machines, it says 'Access denied'. I'm logged in as the same user and have admin rights as well. 

Ps Script which I implemented:

$remoteMachs = 'system1', 'system2', 'system3'
$destination = "\d$\"

foreach($comp in $remoteMachs)
{
if(test-path "\\$comp$destination")
{
Copy-Item D:\MyWorkSpace\SmokeTest -Destination "\\$comp$destination" -Recurse
$session = New-PSSession -ComputerName $comp
icm -Session $session {Start-Process C:\myApp.exe -ArgumentList /SP-, /VERYSILENT, /SUPPRESSMSGBOXES -NoNewWindow} #Intall the app to be tested
Start-Sleep -s 40 # waits for the installation to finish
EndPSS
Set-Content "\\$comp\c$\runTest.bat" -value 'cd \SikuliX\'
Add-Content "\\$comp\c$\runTest.bat" -value 'runScript.cmd -r D:\SmokeTest\src\Login.sikuli'
schtasks /Create /S $comp /tn SmokeTest /tr C:\runTest.bat /sc once /st 17:47:00
}
else
{add-content $logfile "Remote machine $comp failed!"}
}

The above script works well for WIndows 7 machines but fails on Xps.

As a workaround, I tried the following instead of 

PsExec.exe \\$comp schtasks /Create /S $comp /tn "SmokeTest" /tr C:\runTest.bat /sc once /st 18:00:00

The above one threw some Remote Exception, and then displayed "The task will be created under current logged-on user name ("domain\username")."

I can see on the WIndows XP machines that a process gets created in the taskman called PSEXESVC.exe as soon this command is being called. But I cannot see any scheduled tasks in the sytem and the runScript.bat is not getting executed as well. I'm sure that it's not running in the background as well.

And one more question: If I use Register-PSScheduledJob, can I make the job run in the foreground ? (At present it's running in the background only which I can see in the taskman only) Will it run on WIndows Xps as well ?

Help required please..

Thanks in advance !


Viewing all articles
Browse latest Browse all 21975

Trending Articles



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