Get Scheduled Tasks on remote servers

Welcome Forums General PowerShell Q&A Get Scheduled Tasks on remote servers

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years, 2 months ago.

  • Author
  • #5571

    Points: 0
    Rank: Member

    by sh1997 at 2013-02-19 14:12:21

    Below is the script I use to get scheduled tasks running on remote servers:

    (get-content servers.txt) | foreach-object {Schtasks.exe /Query /s $_ /V /FO CSV} | ConvertFrom-CSV |Where { $_.
    TaskName -ne "TaskName"} | Export-CSV c:\test.csv

    the problem is that I received "A network path is not found" for servers that are not available on the network and "Access is denied" for the servers that the script cannot authentiate. I would like to see how the above script with the try..catch statement to capture these errors with the server name. Can someone help?


    by ArtB0514 at 2013-02-20 08:29:32

    Not tested, but I'd start with something like this:
    $TaskData = @()
    foreach ($Server in (get-content servers.txt)) {
    Try {
    Test-Connection $Server -Count 1 -Quiet -ErrorAction Stop
    $TaskData += {Schtasks.exe /Query /s $Server /V /FO CSV} | ConvertFrom-CSV |Where { $_.TaskName -ne "TaskName"}
    Catch {
    "An error occurred connecting to $Server."
    $TaskData | Export-CSV c]

The topic ‘Get Scheduled Tasks on remote servers’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort