cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
AZHockeyNut
Champion Sweeper III
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
4 REPLIES 4
Hendrik_VE
Champion Sweeper III
We use the following workaround to see the scheduled tasks in Lansweeper:

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

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.
vqT4cDoP9iXyMZw
Champion Sweeper
Just checking in, has there been any further development from Lansweeper on collecting Scheduled Task information or is this in the roadmap?
AZHockeyNut
Champion Sweeper III
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). 🙂
Esben_D
Lansweeper Employee
Lansweeper Employee
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.