PowerShell 7.1 -> 5.1 inconsistency with Get-ScheduledTask
See original GitHub issueSteps to reproduce
Get-ScheduledTask
Expected behavior
I would expect the ‘state’ property to be the same across PowerShell 5.1 and PowerShell 7.
This would mean I am returned a state of (Disabled|Ready|Running).
Actual behavior
I am returned an integer, I assume this is an enum.
Environment data
PSVersion 7.1.0
PSEdition Core
GitCommitId 7.1.0
OS Microsoft Windows 6.3.9600
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
scheduled tasks don't show up in Get-ScheduledTask result
To see everything try right clicking the PowerShell icon, select Run as Administrator and then run your Get-ScheduledTask command again and see ...
Read more >Differences between Windows PowerShell 5.1 and ...
This article summarizes the differences and breaking changes from Windows PowerShell 5.1 and the current version of PowerShell that is based ...
Read more >Scheduled Task with Powershell script Failing with PS ...
Hi all, I've noticed that a scheduled task running a powershell script doesn't work on version 5.1.19041.1682. But It does work with version ......
Read more >Get-ScheduledTask -TaskName no longer works on my ...
Hoping someone knows how to make this work again. The command help for -Name is: -Name <Object> The name or name pattern of...
Read more >In an elevated Powershell prompt, why does Get- ...
Type the command Get-ScheduledTask. The expected results are a list of all the scheduled tasks. My actual results are Get-ScheduledTask: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The issue here is most likely due the
ScheduledTask
module not being PowerShell Core compatible on that Windows build. In this case the module is loaded in an implicit remoting session that is connected to a Windows PowerShell process which is what is hosting the module. Because the ScheduledTask module isn’t loaded into the current session there is no special type data to convert the raw int value the MSFT_ScheduledTask returns.You can see the
State
value for the CIM class that hosts this information is a signed integer ([int32]
) so a raw WMI query will return an integerWhere the PowerShell magic comes in is that it has extended type data to make the data more readable
This type data is automatically applied to any type that matches the type name (caveats do apply) so on Windows PowerShell the
State
property as exposed by PowerShell is automatically converted to an enum when it is accessed.Going back to the point where the
ScheduledTask
module is run in an implicit remoting session. The module is now loaded in the Windows PowerShell session whereas your PS Core one does not have any type data. Therefore the State will continue to be the raw Int32 value. Newer Windows builds contain an updatedScheduledTask
module which now loads on PS Core and therefore contain the type data to automatically expose the enum instead.TLDR: The raw value from
Get-ScheduledTask State
is an Int32 but the module has extra type data so it’s converted to an enum when accessed. PS Core doesn’t load the module normally on that older Windows build (because it’s not compatible) so the type data is not present.Just an FYI in the future the default bug report title is quite generic. It makes it easier to search for issues (especially historical ones) if the title reflects the actual bug.