Partager via


Powershell – Get Domain Controllers Scheduled Task

Real quick post for the day. This script is designed to enumerate every Domain Controller in a forest and retrieve all the scheduled task.  Note this script will not work if you run it from Windows 2008 R2 or Windows 7.  You would need to change the script to use get-wmiobject instead. 

 

 $default_log = $env:userprofile + '\Documents\dc_scheduletask_report.csv'
  
 Import-Module activedirectory
  
 ((get-adforest).domains | get-addomain).ReplicaDirectoryServers | foreach {Get-Scheduledtask -CimSession $_ | foreach{$_taskpath = $_.taskpath;$_taskname =$_.taskname; $_taskstate=$_.state;$_.actions | select `
 @{name='DC';expression={$_.PSComputerName}}, `
 @{name='TaskName';expression={$_taskname}}, `  
 @{name='TaskPath';expression={$_taskPath}}, `
 @{name='State';expression={$_taskstate}}, `
 execute, arguments, workingdirectory | export-csv $default_log -append -NoTypeInformation
 }}

 

Link to Script Gallery

 

open the results in excel.

image

Select all the columns

image

Select Insert and Pivot Table

image

Select OK

image

In the pivot Fields drag the field down into the areas like this:

image

There is now a nice little report.

image

Look for instances where the grand total does not contain the number of all the DC’s in the forest.

image

Go and investigate the differences.  I hope you find this useful.  Have a good day.

-Chad