Uncategorized · February 9, 2021 0

Get a scheduled task state locally or remotely

Hi again,

you might be writting an automation script and running in a situation where you want to check status of a specific ScheduledTask. For that let me show you different ways to do that

first way is the one I like 😉 I store the state in a variable and then use the ‘.’ to acccess the real saved state as shown below

$state = Get-ScheduledTask -TaskName "XXXX" | select State
Write-Host $state.State

output will be looking something like that

the second way the one liner, as you can use the below code

(Get-ScheduledTask -TaskName "XXXX" | select State).state

as seen below

Now; if you want to inquiry the status from a remote machine then you have the choose either to combine the above code with invoke command or use the -CimSession command as seen below

$computer = "XXX"

(Get-ScheduledTask -CimSession $computer | Where-Object {$_.TaskName -match "something"}).State

thats it! I hope that was usefull for you.

Happy coding


Close Bitnami banner