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 */