Ce script permet de lister les taches planifiée présente sur une machine.
Le script doit impérativement être lancé en tant que administrateur.
Les tâches “system” présente dans \Microsoft et \Symantec Endpoint Protection sont exclues.
$Res=@()
$lstServers=Get-ADComputer -Filter ‘OperatingSystem -like “*server*” -and Enabled -eq $true’
foreach($Server in $lstServers){
If((Test-Connection -Cn $Server.DNSHostName -BufferSize 16 -Count 1 -ea 0 -Quiet)){
$lstScheduledTask=””
$lstScheduledTask=Get-ScheduledTask -CimSession $Server.DNSHostName
if($lstScheduledTask.count -gt 0){
Foreach($Task in $lstScheduledTask){
If(!$($Task.TaskPath -like “\Microsoft\*” -or $Task.TaskPath -like “\Symantec Endpoint Protection\*”)){
$DataCollect = New-Object System.object
$DataCollect | Add-Member -name ‘DNSHostName’ -MemberType NoteProperty -Value $Server.DNSHostName
$DataCollect | Add-Member -name ‘CnxServer’ -MemberType NoteProperty -Value “OK”
$DataCollect | Add-Member -name ‘TaskName’ -MemberType NoteProperty -Value $Task.TaskName
$DataCollect | Add-Member -name ‘TaskPath’ -MemberType NoteProperty -Value $Task.TaskPath
$DataCollect | Add-Member -name ‘State’ -MemberType NoteProperty -Value $Task.State
$Res+=$DataCollect
}
}
}else{
$DataCollect = New-Object System.object
$DataCollect | Add-Member -name ‘DNSHostName’ -MemberType NoteProperty -Value $Server.DNSHostName
$DataCollect | Add-Member -name ‘CnxServer’ -MemberType NoteProperty -Value “CimSession KO”
$Res+=$DataCollect
}
}else{
Write-host “Failed to connect to: ” $Server.DNSHostName
$DataCollect = New-Object System.object
$DataCollect | Add-Member -name ‘DNSHostName’ -MemberType NoteProperty -Value $Server.DNSHostName
$DataCollect | Add-Member -name ‘CnxServer’ -MemberType NoteProperty -Value “No Ping”
$Res+=$DataCollect
}
}
$Res | FT