Notification

Icon
Error

reporting on scheduled tasks - reporting on scheduled tasks

Posted: Friday, March 22, 2019 5:25:22 PM(UTC)
AZHockeyNut

AZHockeyNut

Member Alpha Tester Original PosterPosts: 236
0
Like
running LS version 7.1.40.5 and I don't see a report on scheduled tasks. Wondering if LS scans those or not.

I found a way to do a report in powershell but it would be cleaner and better in LANSweeper for sure.

Here is the powershell

[cmdletbinding()]
param (
[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[string[]] $ComputerName = $env:computername,
## Get-ADComputer -Filter * | Select -Expand Name
[string] $TaskName
)
#function to get all scheduled task folder details.
function Get-TaskSubFolders {
[cmdletbinding()]
param (
$FolderRef
)
$ArrFolders = @()
$folders = $folderRef.getfolders(1)
if($folders) {
foreach ($folder in $folders) {
$ArrFolders = $ArrFolders + $folder
if($folder.getfolders(1)) {
Get-TaskSubFolders -FolderRef $folder
}
}
}
return $ArrFolders
}

#MAIN
#$ComputerName = Get-ADComputer -Filter * | Select -Expand Name

foreach ($Computer in $ComputerName) {
$SchService = New-Object -ComObject Schedule.Service
$SchService.Connect($Computer)
$Rootfolder = $SchService.GetFolder("\")
$folders = @($RootFolder)
$folders += Get-Tasksubfolders -FolderRef $RootFolder
foreach($Folder in $folders) {
$Tasks = $folder.gettasks(1)
foreach($Task in $Tasks) {
$OutputObj = New-Object -TypeName PSobject
$OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer
$OutputObj | Add-Member -MemberType NoteProperty -Name TaskName -Value $Task.Name
$OutputObj | Add-Member -MemberType NoteProperty -Name TaskFolder -Value $Folder.path
$OutputObj | Add-Member -MemberType NoteProperty -Name IsEnabled -Value $task.enabled
$OutputObj | Add-Member -MemberType NoteProperty -Name LastRunTime -Value $task.LastRunTime
$OutputObj | Add-Member -MemberType NoteProperty -Name LastTaskResult -Value $task.LastTaskResult
$OutputObj | Add-Member -MemberType NoteProperty -Name NextRunTime -Value $task.NextRunTime
$OutputObj | Add-Member -MemberType NoteProperty -Name State -Value $task.State
$OutputObj | Add-Member -MemberType NoteProperty -Name TaskFolderPath -Value $task.Path

if($TaskName) {
if($Task.Name -eq $TaskName) {
$OutputObj
}
} else {
$OutputObj
}
}

}


}



Save it as a file called findscheduledtasks.ps1
then you can run it in powershell (I used an administrative powershell just in case)

.\findscheduledtasks.ps1 | ConvertTo-Html -Property ComputerName,TaskName,Folder,IsEnabled,State,LastRunTime,LastTaskResult,NextRunTime, TaskFolderPath -Head $Header | Out-File -FilePath scheduledtasks.html


The Output is a file in your folder called "Scheduledtasks.html" open in your browser and you get a table from your local system scheduled tasks.

uncomment this line "#$ComputerName = Get-ADComputer -Filter * | Select -Expand Name" and it will scan all systems from AD that you have access too, that could take a while.


WARNING, I cobbled together several scripts and examples I found on the web to make this work. I am not very good at Powershell and even worse at HTML, there is a lot to improve upon, which is why I was thinking LS could do this


Forum Admins, if you don't like this post or feel it is miscategorized etc, feel free to move/delete it and let me know.
Thanks
Esben.D
#1Esben.D Member Administration Posts: 1,982  
posted: 3/25/2019 9:21:28 AM(UTC)
It's not possible at the moment, the only way I can think of doing it by using Lansweeper would be to write the info the script gathers in registry keys and scan those.
AZHockeyNut
#2AZHockeyNut Member Alpha Tester Original PosterPosts: 236  
posted: 3/25/2019 7:45:34 PM(UTC)
OK I think what I might do is make a report in html that is what I am looking for then attach that to a tab on the dashboard for now until you guys get it into the app (assuming some day you will). :)
vqT4cDoP9iXyMZwoDUWU
#3vqT4cDoP9iXyMZwoDUWU Member Posts: 17  
posted: 9/15/2020 4:54:02 PM(UTC)
Just checking in, has there been any further development from Lansweeper on collecting Scheduled Task information or is this in the roadmap?
Hendrik.VE
#4Hendrik.VE Member Posts: 45  
posted: 9/16/2020 8:23:44 AM(UTC)
We use the following workaround to see the scheduled tasks in Lansweeper:

- Run the following simple PowerShell oneliner (eg. using deployment):

Code:
Get-ScheduledTask -TaskPath "\" | Get-ScheduledTaskInfo | % {$str = "TaskName : " ;$str += $_.TaskName; $str += " ; Lastruntime : ";$str += $_.Lastruntime; $str += " ; LastTaskResult : "; $str += $_.LastTaskResult; EventCreate /so SchedTask /L Application /T Error /ID 1000 /D $str}


- Rescan your asset(s) and check the Event log tab

We didn't create any report yet as we only use this workaround 'on the fly' to collect specific information.

PS. instead of using the deployment feature we use McAfee ePO to run PowerShell or other scripts. No credentials or other complex configuration needed. If you want to collect the output from your scripts you can parse it either to a (custom) registry key or to the Event Log.

Active Discussions

Lansweeper Last used system of users in a specific OU
by  chriscornelis   Go to last post Go to first unread
Last post: Yesterday at 11:11:35 AM(UTC)
Lansweeper Trying to display different versions of software
by  TimHolmes1973  
Go to last post Go to first unread
Last post: 10/28/2020 8:54:04 PM(UTC)
Lansweeper Switch & Port reports - SNMPInfo tables missing info
by  Maxlieb   Go to last post Go to first unread
Last post: 10/28/2020 1:02:24 PM(UTC)
Lansweeper Last Patch Date
by  Dan S   Go to last post Go to first unread
Last post: 10/26/2020 2:27:47 PM(UTC)
Lansweeper Webcam report, the wrong way
by  TimHolmes1973  
Go to last post Go to first unread
Last post: 10/23/2020 4:38:45 PM(UTC)
Lansweeper zerologin posted report
by  hanslepire   Go to last post Go to first unread
Last post: 10/23/2020 8:50:59 AM(UTC)
Lansweeper Need help finishing a report for Failed Logons
by  Helpdesk15  
Go to last post Go to first unread
Last post: 10/20/2020 3:10:33 PM(UTC)