Link to home
Start Free TrialLog in
Avatar of Nik
NikFlag for Croatia

asked on

How to export Scheduled Jobs from DC's via VBS or Powershell script

Hello to all,

I need to export all scheduled tasks from our Domain Controllers via VBS or PowerShell Script.
Does anyone had similar need and maybe has finished code to share?

Thanks
Avatar of markpalinux
markpalinux
Flag of United States of America image



schtasks - maybe helpful

You may read that it depends on how they were scheduled. If they were scheduled with at then the step below will not work, if they were scheduled with task scheduler then it should work.

this page discusses Win32_Win32_ScheduledJob
http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept04/hey0922.mspx

Mark
Avatar of jss1199
jss1199

Use the below command line and capture the output and paste into a blank XML file.  You can then import and/or modify the XML

schtasks /Query [/S  [/U  [/P []]] /XML /TN
try this
Set objShell = CreateObject("WSCript.shell")
strServer = InputBox("enter server name")
strPath = InputBox("path to save csv file. e.g : c:\temp")
strCmd = "cmd /c schtasks /query /S \\" & strServer & " /V /FO CSV >" & Chr(34) & strPath & "\" & strServer & ".csv" & chr(34)
objShell.Run(strCmd,0,True)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of yehudaha
yehudaha
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can just copy the .job files from \\servername\admin$\tasks.  They can be exported to other machines by copying them to the same location.  Usually only the "Run As" parameter has to be adjusted afterwards.
Avatar of Nik

ASKER

Thank you all for your kind help.

I will try every suggestion and see which will be the best for my needs.

Basically I need the following:

- Name of the Scheduled Task/s (it's essential that I have a list of all running tasks on the server)
- I need it to get that info from around 20 DC's
- Most important thing is that I get the account name which is used to run the scheduled task.

Output file version is insubstantial. .csv, .xml etc, any will do.

Thx, regards,
Nik
Avatar of Nik

ASKER

That's exactly what I needed. Thanks
thanks for the grade
Avatar of Nik

ASKER

I've changed it a bit for our needs, but it was very helpful. Thanks again.
Avatar of Nik

ASKER

BTW, thank you all who participated in this question.