I am new to Powershell and dynamic state configuration. I am trying to get a deployment script working that will set up a number of tasks in the Windows task scheduler. I have written the script and have been trying to run it on my local machine.

Configuration AppServerTasks {
    param($NodeName)
    Import-DscResource -Module StackExchangeResources    

    Node $NodeName
    {
        $trackingFilePath = "...";
        $tracksFilePath = "...";
        $reportingFilePath = "...";

        ScheduledTask TrackTask
        {
            Name = "Tracks"
            FilePath = $tracksFilePath
            Daily = $true
            Hours = 0
            Minutes = 5
        }

        ScheduledTask TrackingTask
        {
            Name = "Tracking"
            FilePath = $trackingFilePath
            Daily = $true
            Hours = 0
            Minutes = 5
        }

        ScheduledTask ReportingTask
        {
            Name = "Reporting"
            FilePath = $reportingFilePath
            Daily = $true
            Hours = 0
            Minutes = 5
        }
    }
}

AppServerTasks -NodeName "localhost"
Start-DscConfiguration AppServerTasks -Wait -Verbose -Force

However, this is failing with "Access is denied". The error I get from this is as follows:

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 MEEP with user sid S-1-5-21-2331283068-2376342717-1560730737-1001.
VERBOSE: [MEEP]: LCM:  [ Start  Set      ]
VERBOSE: [MEEP]: LCM:  [ Start  Resource ]  [[ScheduledTask]TrackTask]
VERBOSE: [MEEP]: LCM:  [ Start  Test     ]  [[ScheduledTask]TrackTask]
VERBOSE: [MEEP]:                            [[ScheduledTask]TrackTask] Unable to find matching job.
VERBOSE: [MEEP]: LCM:  [ End    Test     ]  [[ScheduledTask]TrackTask]  in 0.0160 seconds.
VERBOSE: [MEEP]: LCM:  [ Start  Set      ]  [[ScheduledTask]TrackTask]
Connecting to remote server MEEP failed with the following error message : Access is denied. For more information, see the 
about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:) [], CimException
    + FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed
    + PSComputerName        : localhost

Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or 
empty, and then try the command again.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
    + PSComputerName        : localhost

Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or 
empty, and then try the command again.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
    + PSComputerName        : localhost

VERBOSE: [MEEP]: LCM:  [ End    Set      ]  [[ScheduledTask]TrackTask]  in 0.0150 seconds.
The PowerShell DSC resource StackExchange_ScheduledTask threw one or more non-terminating errors while running the 
Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. 
Refer to this channel for more details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : localhost

VERBOSE: [MEEP]: LCM:  [ Start  Resource ]  [[ScheduledTask]TrackingTask]
VERBOSE: [MEEP]: LCM:  [ Start  Test     ]  [[ScheduledTask]TrackingTask]
VERBOSE: [MEEP]:                            [[ScheduledTask]TrackingTask] Unable to find matching job.
VERBOSE: [MEEP]: LCM:  [ End    Test     ]  [[ScheduledTask]TrackingTask]  in 0.0000 seconds.
VERBOSE: [MEEP]: LCM:  [ Start  Set      ]  [[ScheduledTask]TrackingTask]
Connecting to remote server MEEP failed with the following error message : Access is denied. For more information, see the 
about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:) [], CimException
    + FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed
    + PSComputerName        : localhost

Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or 
empty, and then try the command again.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
    + PSComputerName        : localhost

Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or 
empty, and then try the command again.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
    + PSComputerName        : localhost

VERBOSE: [MEEP]: LCM:  [ End    Set      ]  [[ScheduledTask]TrackingTask]  in 0.0320 seconds.
The PowerShell DSC resource StackExchange_ScheduledTask threw one or more non-terminating errors while running the 
Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. 
Refer to this channel for more details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : localhost

VERBOSE: [MEEP]: LCM:  [ Start  Resource ]  [[ScheduledTask]ReportingTask]
VERBOSE: [MEEP]: LCM:  [ Start  Test     ]  [[ScheduledTask]ReportingTask]
VERBOSE: [MEEP]:                            [[ScheduledTask]ReportingTask] Unable to find matching job.
VERBOSE: [MEEP]: LCM:  [ End    Test     ]  [[ScheduledTask]ReportingTask]  in 0.0000 seconds.
VERBOSE: [MEEP]: LCM:  [ Start  Set      ]  [[ScheduledTask]ReportingTask]
Connecting to remote server MEEP failed with the following error message : Access is denied. For more information, see the 
about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:) [], CimException
    + FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed
    + PSComputerName        : localhost

Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or 
empty, and then try the command again.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
    + PSComputerName        : localhost

Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or 
empty, and then try the command again.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
    + PSComputerName        : localhost

VERBOSE: [MEEP]: LCM:  [ End    Set      ]  [[ScheduledTask]ReportingTask]  in 0.0150 seconds.
The PowerShell DSC resource StackExchange_ScheduledTask threw one or more non-terminating errors while running the 
Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. 
Refer to this channel for more details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : localhost

The SendConfigurationApply function did not succeed.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost

VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.139 seconds

I have tried Googling (as I don't know the cause of context of the problem). But it has not helped as, although others have gotten similar problems to this, the fixes suggested have not worked. I am running this in POwershell ISE as Administrator. I have tried Enable-PSRemoting -force and it is enabled. Not sure what to do next.

Your thoughts? Thanks.

1

There are 1 answers

4
Kiran Reddy On

Seems credentials are necessary:

$ConfigurationData = @{
AllNodes = @(
    @{
        NodeName="*"
        PSDscAllowPlainTextPassword=$true
     }
    @{
        NodeName="Localhost"
     }
)
}

Configuration AppServerTasks {
param($NodeName,$credential)

Import-DscResource -ModuleName StackExchangeResources

Node $AllNodes.NodeName 
{

    $trackingFilePath = 'c:\temp\test.ps1'


    ScheduledTask TrackTask
    {
        Name = "Tracks"
        FilePath = $trackingFilePath
        Daily = $true
        Hours = 0
        Minutes = 5
        Credential = $credential
    }

}
}

$c = Get-Credential
AppServerTasks -ConfigurationData $ConfigurationData  -OutputPath          c:\temp\localhost -credential $c
Start-DscConfiguration -ComputerName localhost -Path C:\temp\localhost -Wait -Verbose -Force