→ 🚀What's New? Explore Lansweeper's Fall 2024 Updates! Fall Launch Blog !
‎03-22-2019 05:25 PM
[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
}
}
}
}
‎09-16-2020 09:23 AM
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}
‎09-15-2020 05:54 PM
‎03-25-2019 07:45 PM
‎03-25-2019 09:21 AM
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now