Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell script to show scheduled tasks history details and its properties ?

$
0
0

People,

This script originally can display the Server name, Scheduled Task name and the Service Account Name.

Import-Module ActiveDirectory
$VerbosePreference = "continue"
$list = Get-ADComputer -Properties Name  -Filter {Enabled -eq $True -and OperatingSystem -like "*Windows Server*"} -SearchBase "OU=Servers,DC=domain,DC=com" |
	        Where-Object {Test-Connection $_.Name -Count 1 -Quiet} |
	        Select-Object -ExpandProperty Name

Write-Verbose -Message "Trying to query $($list.count) servers found in AD"
$logfilepath = "C:\RESULT\SchedTaskServers.csv"
$ErrorActionPreference = "SilentlyContinue"

foreach ($computername in $list)
{
    $path = "\\" + $computername + "\c$\Windows\System32\Tasks"
    $tasks = Get-ChildItem -Path $path -File

    if ($tasks)
    {
        Write-Verbose -Message " $($tasks.count) tasks for $computername"
    }

    foreach ($item in $tasks)
    {
        $AbsolutePath = $path + "\" + $item.Name
        $task = [xml] (Get-Content $AbsolutePath)
        [STRING]$check = $task.Task.Principals.Principal.UserId

        if ($task.Task.Principals.Principal.UserId)
        {
          Write-Verbose -Message "Writing the log file with values for $computername"
          Add-content -path $logfilepath -Value "$computername,$item,$check"
        }

    }
}

Can anyone here please assist me in modifying the script above so that it can show the Last running time and the Status/Result from lists of Windows Server ?

Thanks.


/* Server Support Specialist */


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>