Forum Discussion
Check Disabled state after Disable-ScheduledTask status on Running Task
- Jun 08, 2023
Hi,
Sorry, try this instead, which checks the Settings.Enabled property:
Get-ScheduledTask -TaskName "SystemSoundsService" | ForEach-Object { [PSCustomObject] @{ Task = "$($_.TaskPath)$($_.TaskName)"; State = $_.State; Enabled = $_.Settings.Enabled; } }
The principle is the same as for Triggers, it's just that the Settings.Enabled describes the job as a whole rather than Triggers.Enabled that returns the status of each trigger in the Triggers array.
Cheers,
Lain
Hello LainRobertson
thank you for your fast reply. I think i understand your State and Trigger explanation. However, the trigger comes back the same enabled : True, when the task is enabled or disabled.
Looking at your script i am a bit confused. You are running a foreach-object, but there seems to be only one state and one trigger property for a service, as far as i can see. For example:
$task = Get-ScheduledTask -TaskName "RtkAudUService64_BG" -TaskPath \
$task | Get-Member
TypeName: Microsoft.Management.Infrastructure.CimInstance#Root/Microsoft/Windows/TaskScheduler/MSFT_ScheduledTask
Name MemberType Definition
---- ---------- ----------
Dispose Method void Dispose(), void IDisposable.Dispose()
Equals Method bool Equals(System.Object obj)
GetCimSessionComputerName Method string GetCimSessionComputerName()
GetCimSessionInstanceId Method guid GetCimSessionInstanceId()
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Actions Property CimInstance#InstanceArray Actions {get;set;}
Author Property string Author {get;set;}
Date Property string Date {get;set;}
Description Property string Description {get;set;}
Documentation Property string Documentation {get;set;}
Principal Property CimInstance#Instance Principal {get;set;}
PSComputerName Property string PSComputerName {get;}
SecurityDescriptor Property string SecurityDescriptor {get;set;}
Settings Property CimInstance#Instance Settings {get;set;}
Source Property string Source {get;set;}
TaskName Property string TaskName {get;}
TaskPath Property string TaskPath {get;}
Triggers Property CimInstance#InstanceArray Triggers {get;set;}
URI Property string URI {get;}
Version Property string Version {get;set;}
State ScriptProperty System.Object State {get=[Microsoft.PowerShell.Cmdletization.GeneratedTypes.ScheduledTask.StateEnum]($this.PSBase.CimInstanceProperti
$task.Triggers
Enabled : True
EndBoundary :
ExecutionTimeLimit :
Id :
Repetition : MSFT_TaskRepetitionPattern
StartBoundary :
Delay : PT30S
UserId :
PSComputerName :
Or do you mean that every object has a corresponding trigger in WMI MSFT_TaskLogonTrigger object?
Sorry for the confusion 😞
i was poking around the system where could i see some additional info and i found this, when running schtasks /query:
PS C:\Windows\System32> schtasks /query /TN "\RtkAudUService64_BG" /XML
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2010-07-30T20:43:10</Date>
<Author>Realtek</Author>
<URI>\RtkAudUService64_BG</URI>
</RegistrationInfo>
<Principals>
<Principal id="Author">
<GroupId>S-1-5-32-545</GroupId>
</Principal>
</Principals>
<Settings>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<Enabled>false</Enabled>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
<IdleSettings>
<Duration>PT10M</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>false</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
</Settings>
<Triggers>
<LogonTrigger>
<Delay>PT30S</Delay>
</LogonTrigger>
</Triggers>
<Actions Context="Author">
<Exec>
<Command>""C:\WINDOWS\System32\DriverStore\FileRepository\realtekservice.inf_amd64_ed3f04e1261e4822\RtkAudUService64.exe""</Command>
<Arguments>-background</Arguments>
</Exec>
</Actions>
</Task>
The <Enabled>false</Enabled> line in Settings, is visible only when the task is disabled.
I would rather however use the PowerShell commandlets, to get the values.
- LainRobertsonJun 08, 2023Silver Contributor
Hi,
Sorry, try this instead, which checks the Settings.Enabled property:
Get-ScheduledTask -TaskName "SystemSoundsService" | ForEach-Object { [PSCustomObject] @{ Task = "$($_.TaskPath)$($_.TaskName)"; State = $_.State; Enabled = $_.Settings.Enabled; } }
The principle is the same as for Triggers, it's just that the Settings.Enabled describes the job as a whole rather than Triggers.Enabled that returns the status of each trigger in the Triggers array.
Cheers,
Lain
- RedModSKJun 08, 2023Copper Contributor
LainRobertson
Thats it, thank you mate!
I am surprised and a bit ashamed, that i did not see it when i was going through the properties.
Cheers