ScheduledTask - Cannot disable "Microsoft Compatibility Appraiser"
Details of the scenario you tried and the problem that is occurring
Trying to disable "Microsoft Compatibility Appraiser" Schedule task generates an error.
Verbose logs showing the problem
VERBOSE: [servername]: [[ScheduledTask]DisableMicrosoftCompatibilityAppraiser] Disabling existing scheduled task 'Microsoft Compatibility Appraiser' in '\Microsoft\Windows\Application Experience'. The parameter is incorrect. + CategoryInfo : InvalidArgument: (PS_ScheduledTask:) [], CimException + FullyQualifiedErrorId : HRESULT 0x80070057,Register-ScheduledTask + PSComputerName : localhost
VERBOSE: [servername]: LCM: [ End Set ] [[ScheduledTask]DisableMicrosoftCompatibilityAppraiser] in 0.7970 seconds.
Suggested solution to the issue
The DSC configuration that is used to reproduce the issue (as detailed as possible)
# insert configuration here
Configuration SchdTaskTest
{
Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName ComputerManagementDsc
Node localhost
{
ScheduledTask DisableMicrosoftCompatibilityAppraiser
{
TaskName = 'Microsoft Compatibility Appraiser'
TaskPath = '\Microsoft\Windows\Application Experience\'
Enable = $false
}
ScheduledTask DisableSchdTaskApplicationExperienceProgramDataUpdator
{
TaskName = 'ProgramDataUpdater'
TaskPath = '\Microsoft\Windows\Application Experience\'
Enable = $false
}
}
}
SchdTaskTest
The operating system the target node is running
OsName: Microsoft Windows Server 2016 Datacenter OsOperatingSystemSKU: DatacenterServerEdition OsArchitecture: 64-bit WindowsBuildLabEx: 14393.3442.amd64fre.rs1_release.191219-1727 OsLanguage: en-US OsMuiLanguages: {en-US, en-GB}
Version and build of PowerShell the target node is running
PSVersion 5.1.14393.3383
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.3383
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Version of the DSC module that was used ('dev' if using current dev branch)
ComputerManagementDsc 7.1.0.0
More detail.... I've tried this on various machines, even a vanilla VM deployed in Azure using the Microsoft image from the Marketplace and it always fails.
The issue seems to be related to scheduled tasks that have "Mulitple triggers defined".
These all fail with the same error
I found a solution (for windows 10) There is a surcharge of function in DSC_Scheduledtask.psm1 :
function Disable-ScheduledTask
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$TaskName,
[Parameter()]
[System.String]
$TaskPath = '\'
)
$existingTask = ScheduledTasks\Get-ScheduledTask @PSBoundParameters
$existingTask.Settings.Enabled = $false
$null = $existingTask | Register-ScheduledTask @PSBoundParameters -Force
}
It must be commented, and now it's working...