Scheduled Tasks Properties in PowerShell?

8,559

Use the /fo parameter in schtasks to print the output as CSV and then convert the output to a Powershell object with the ConvertFrom-CSV command.

$tasks = schtasks /query /fo CSV | ConvertFrom-CSV

You can then use search for a particular task name as follows

$myTask = $tasks | Where-Object {$_.TaskName -eq "My_Scheduled_Task"}
Share:
8,559

Related videos on Youtube

nulz
Author by

nulz

Updated on September 18, 2022

Comments

  • nulz
    nulz over 1 year

    I am not sure how to do this in PowerShell, but I dont think it is supported.

    For example:

    $tasks = schtasks /query 
    

    Will store all the tasks into the variable $tasks

    Example output:

    Folder: \Microsoft\Windows\WindowsBackup
    TaskName                                 Next Run Time          Status
    ======================================== ====================== ===============
    ConfigNotification                       Disabled
    

    The property "TaskName" cannot be referred to that easily (ie $tasks.TaskName)

    Is there some other way to refer to the TaskName property within the $tasks variable, sort of like how you can reference properties in the get-service cmdlet?

    $services = gsv
    $services | Where-Object { Write-Output $_.Name }
    
    • nulz
      nulz almost 13 years
      Has something to do with Select-String, but I do not know how to configure it
    • user3113103
      user3113103 almost 13 years
      added the script to my answer; hope it helps you out