Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DSCPlatformIssue]New-ScheduledTaskTrigger not compatible with PowerShell 4 and 5 #58

Open
cveld opened this issue Mar 9, 2016 · 3 comments
Assignees

Comments

@cveld
Copy link

cveld commented Mar 9, 2016

I am getting the following exception when trying out the cScheduleTask resource:
Method "NewTriggerByDaily" not found + CategoryInfo : ObjectNotFound: (PS_ScheduledTask:) [], CimException + FullyQualifiedErrorId : HRESULT 0x80041002,New-ScheduledTaskTrigger + PSComputerName : localhost

This is on a Windows 7 laptop with PowerShell 4 and on a Windows 10 laptop with PowerShell 5 installed.

I have found the following forum discussion that seems to contain the answer:
http://powershell.org/wp/forums/topic/method-newtriggerbyonce-not-found-taskscheduler/

It looks like New-ScheduledTaskTrigger -Daily -At '11AM' constructions need to be replaced by New-JobTrigger -Daily -At 11AM.
I have tested these two expressions on my test devices and both respond as expected, i.e. the first generates the exception New-ScheduledTaskTrigger : Method "NewTriggerByDaily" not found whereas the second replies with a JobTrigger object.

@guitarrapc
Copy link
Owner

Thank you for reporting.

I knew there are Bug with New-ScheduledTaskTrigger on WMF5, includes Windows 10, with -Daily, Once, Weekly and others. You can find this bug in UserVoice https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/11190663-bug-scheduledtasks-module-broken-in-1511

Unfortunately your proposal, and also link to the powershell.org, New-JobTrigger -Daily -At 11AM describe not a ScheduledTask but about ScheduledJob. As you can see this resource is about ScheduledTask not a ScheduledJob. Because they are completely interface incompatible each other. ScheduledJob Type couldn't be used for ScheduledTask.

PS C:\Users\> $trigger = New-JobTrigger -Daily -At 11AM | gm
PS C:\Users\> $action = New-ScheduledTaskAction -Execute powershell.exe
PS C:\Users\> New-ScheduledTask -Action $action -Trigger $trigger
New-ScheduledTask : Cannot process argument transformation on parameter 'Trigger'. Cannot convert the "bool
Equals(System.Object obj)" value of type "Microsoft.PowerShell.Commands.MemberDefinition" to type
"Microsoft.Management.Infrastructure.CimInstance".
At line:1 char:44
+ New-ScheduledTask -Action $action -Trigger $trigger
+                                            ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-ScheduledTask], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,New-ScheduledTask

Future Plan

So what the option? Yes I have idea with, however this idea is completely through away PowerShell ScheduledTask Module and shift all logic to C#. I already implement for C#, works perfect in production, but not yet ported to PowerShell.

Question

Do you experience same issue on Windows Server 2012 R2 WMF4 and WMF5 RTM? I have tested with Windows Server 2012 R2 + WMF4 (w/Nov update) without any issue but not yet for other environment.

I just want to know whether this issue is limited or give up with PowerShell ScheduledTask Module, sigh.... :(

@cveld
Copy link
Author

cveld commented Mar 11, 2016

I quickly tested on a 2012R2 server with the following $PSVersionTable and
I don't get the exception:

Name Value


PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.3.9600.17400
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2

2016-03-09 18:56 GMT+01:00 Ikiru Yoshizaki notifications@github.com:

Thank you for reporting.

I knew there are Bug with New-ScheduledTaskTrigger on WMF5, includes
Windows 10, with -Daily, Once, Weekly and others.

Unfortunately your proposal, and also link to the powershell.org, New-JobTrigger
-Daily -At 11AM describe not a ScheduledTask but about ScheduledJob. As
you can see this resource is about ScheduledTask not a ScheduledJob.
Because they are completely interface incompatible each other.
ScheduledJob Type couldn't be used for ScheduledTask.

PS C:\Users> $trigger = New-JobTrigger -Daily -At 11AM | gm
PS C:\Users> $action = New-ScheduledTaskAction -Execute powershell.exe
PS C:\Users> New-ScheduledTask -Action $action -Trigger $triggerNew-ScheduledTask : Cannot process argument transformation on parameter 'Trigger'. Cannot convert the "boolEquals(System.Object obj)" value of type "Microsoft.PowerShell.Commands.MemberDefinition" to type"Microsoft.Management.Infrastructure.CimInstance".
At line:1 char:44+ New-ScheduledTask -Action $action -Trigger $trigger+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [New-ScheduledTask], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,New-ScheduledTask

Future Plan

So what the option? Yes I have idea with, however this idea is completely
through away PowerShell ScheduledTask Module and shift all logic to C#. I
already implement for C#, works perfect in production, but not yet ported
to PowerShell.
Question

Do you experience same issue on Windows Server 2012 R2 WMF4 and WMF5 RTM?
I have tested with Windows Server 2012 R2 + WMF4 (w/Nov update) without any
issue but not yet for other environment.

I just want to know whether this issue is limited or give up with
PowerShell ScheduledTask Module, sigh.... :(


Reply to this email directly or view it on GitHub
https://github.com/guitarrapc/DSCResources/issues/58#issuecomment-194424077
.

@guitarrapc
Copy link
Owner

Thank you cveld,

It might be better through PowerShell away and use C# Implementation.

I will do it, please wait a moment.

@guitarrapc guitarrapc self-assigned this Mar 12, 2016
@guitarrapc guitarrapc changed the title New-ScheduledTaskTrigger not compatible with PowerShell 4 and 5 [DSCPlatformIssue]New-ScheduledTaskTrigger not compatible with PowerShell 4 and 5 Mar 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants