guitarrapc / GraniResource

PowerShell Desired State Configuration Resources for real production workload.
https://www.powershellgallery.com/packages/GraniResource
MIT License
44 stars 8 forks source link

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

Open cveld opened 8 years ago

cveld commented 8 years ago

I am getting the following exception when trying out the cScheduleTask resource: `Method "NewTriggerByDaily" not found

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

Thank you cveld,

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

I will do it, please wait a moment.