How to edit a scheduled task trigger - powershell

$taskExists = Get-ScheduledTask $strTaskName
if($taskExists) {
$taskExists.Description = "a daily Report"
$taskExists | set-scheduledtask -user $strUser -Password $strPassword
}
The above piece of power shell code is to update existing schedule task. Could anyone please tell me how to update the trigger values?

The task returned from the Get-ScheduledTask cmdlet has a Triggers property where you can add / remove triggers.

Related

Delete task from task scheduler based on userid powershell

I need to find tasks which runs using SYSTEM and delete rest of the tasks running using any other account
I was trying to find the job first, then unregister, but not getting any filters to do that.
Get-ScheduledTask -TaskName "SPOC_Inventory"
Need help in this
Try this (without -whatif):
PS C:\> Get-ScheduledTask SPOC_Inventory | ? {($_.Principal.UserId -ne "SYSTEM")}| Unregister-ScheduledTask -WhatIf
Enjoy
tom

how to set trigger "on connection to user session" in task scheduler from powershell?

I want to schedule a task in task scheduler from Powershell.
I want to set 2 trigger "On connection to user session" with local and remote both.
And also,I want to uncheck some settings and conditions in case if they are marked in task scheduler.
Can someone please tell me how to set above trigger and how to unchheck settings and conditions?
Thank You
The only way i have found to accomplish that is by creating a new task using the UI. Then export the task to XML.
Then use powershell command for creating a new task by importing the XML.
Register-ScheduledTask -Xml (Get-Content "your-exported.xml" | Out-String) -TaskName "some task name"
you can also add credentials to the command if needed, hence
Register-ScheduledTask -Xml (Get-Content "your-exported.xml" | Out-String) -TaskName "some task name" -User "domain\user" -Password "pa55w0rd"

Change a property of a task in task scheduler using powershell

I have two triggers in a task. The first one runs at a specific time. The second one starts at logon and runs every 10 minutes. I have many similar tasks like this situation. I want to use powershell to change the property from 10 minutes to 5 minutes and run indefinitely after logon. How do I specify the SECOND trigger?
$Task = Get-ScheduledTask -TaskName "Task"
$Task.Triggers.LogonTriggers.Repetition.Duration = ""
$Task.Triggers.Repetition.Interval = "PT10M"
You can modify the $Task object and pass it into the Set-ScheduledTask which will apply the changes you've made. The first trigger that runs at a specific time will have it's StartBoundary property set, the second trigger which starts at Logon won't have this property set so we'll use the value of that to make sure we change the correct trigger.
$Task = Get-ScheduledTask -TaskName "Task"
$RepeatingTrigger = $Task.Triggers | Where-Object { $_.StartBoundary -eq $null }
$RepeatingTrigger.Repetition.Interval = "PT5M"
Set-ScheduledTask -InputObject $Task

How to Get Friendly Description For Scheduled Task Trigger in Powershell

Following https://stackoverflow.com/a/32732879/1378356, I can get a scheduled task's trigger using this syntax:
$task = Get-ScheduledTask -TaskName "SomeTaskName"
$taskTrigger = $task.Triggers[0]
$taskTrigger
But how do I see the friendly name (which is displayed in the Task Scheduler UI), such as "At 8:00 am every Monday"?

Update a Scheduled Task Action using Powershell 4.0

I have already searched this site and also done a good amount of googling and I am unable to find a why to do this.
I want to be able to update the action/s on a scheduled task using PS 4.0.
I don't mind if it means an action to delete the current Action and adding a new one.
Does anyone know if this is possible?
You can use the following to replace the current action with a new action object in a scheduled task.
$Action = New-ScheduledTaskAction -Execute "PowerShell.exe"
Set-ScheduledTask -TaskName "YourTaskName" -Action $Action
This will set a new action to run powershell.exe in a scheduled task.