PowerShellOrg / StackExchangeResources

DSC Resources from Stack Exchange
MIT License
13 stars 8 forks source link

Issues using ScheduledTask #7

Open kevinsea opened 9 years ago

kevinsea commented 9 years ago

I'm trying to use DSC to create scheduled tasks. I run the code below and it appears successful and there are no issues in the event log, but a task is not created.

Configuration Misc
{
    param([PSCredential] $creds)

    Import-DscResource -ModuleName  StackExchangeResources

    Node localhost
    {

        ScheduledTask Test_Task
        {
            Ensure = "Present"
            Name = "Proto2"
            FilePath = "D:\DSCTest\myapp.exe"  
            At = "11:00"
            Credential = $creds
            Daily = $true
            #sint32 Hours; sint32 Minutes; boolean Once; int32 DaysInterval; string DaysOfWeek[]; boolean Weekly;   
        }

    }
}

cls

$myCreds = New-Object System.Management.Automation.PSCredential("NT AUTHORITY\NETWORK SERVICE") 

#I've also tried supply my admin creds $myCreds = Get-Credential

Misc($myCreds)  -OutputPath "C:\Admin\TestingStuff\PS\DSC1\Misc"

Start-DscConfiguration -Path "C:\Admin\TestingStuff\PS\DSC1\Misc" -Wait -Verbose -Force -Debug 

Results: VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'. VERBOSE: An LCM method call arrived from computer USB-TGKCTEST with user sid S-1-5-21-2950772361-2964733660-914393307-1001. VERBOSE: [USB-TGKCTEST]: LCM: [ Start Set ] VERBOSE: [USB-TGKCTEST]: LCM: [ Start Resource ] [[ScheduledTask]Test_Task::[Misc]System.Management.Automation.PSCredential::[Misc]System.Management.Automation.PSCredential] VERBOSE: [USB-TGKCTEST]: LCM: [ Start Test ] [[ScheduledTask]Test_Task::[Misc]System.Management.Automation.PSCredential::[Misc]System.Management.Automation.PSCredential] VERBOSE: [USB-TGKCTEST]: [[ScheduledTask]Test_Task::[Misc]System.Management.Automation.PSCredential::[Misc]System.Management.Automation.PSCredential] Unable to find matching job. VERBOSE: [USB-TGKCTEST]: LCM: [ End Test ] [[ScheduledTask]Test_Task::[Misc]System.Management.Automation.PSCredential::[Misc]System.Management.Automation.PSCredential] in 0.5160 seconds. VERBOSE: [USB-TGKCTEST]: LCM: [ Start Set ] [[ScheduledTask]Test_Task::[Misc]System.Management.Automation.PSCredential::[Misc]System.Management.Automation.PSCredential] VERBOSE: [USB-TGKCTEST]: LCM: [ End Set ] [[ScheduledTask]Test_Task::[Misc]System.Management.Automation.PSCredential::[Misc]System.Management.Automation.PSCredential] in 0.9530 seconds. VERBOSE: [USB-TGKCTEST]: LCM: [ End Resource ] [[ScheduledTask]Test_Task::[Misc]System.Management.Automation.PSCredential::[Misc]System.Management.Automation.PSCredential] VERBOSE: [USB-TGKCTEST]: LCM: [ End Set ] in 1.8358 seconds. VERBOSE: Operation 'Invoke CimMethod' complete. VERBOSE: Time taken for configuration job to complete is 2.025 seconds

tuespetre commented 8 years ago

It's because this resource is using 'scheduled jobs' rather than 'scheduled tasks', so it only accepts PowerShell files. I just found this out as well...

I think the -ErrorAction SilentlyContinue needs to be removed from this:

https://github.com/PowerShellOrg/StackExchangeResources/blob/master/DSCResources/StackExchange_ScheduledTask/StackExchange_ScheduledTask.psm1#L226