Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell New-ScheduledTaskSettingsSet

I try to add New-ScheduledTaskSettingsSet with custom settings. As per Technet, there is possible options for MultipleInstances and including StopExisting value.

enter image description here

But actual powershell allows me choose only Parallel, Queue or IgnoreNew.

Why I can't use StopExisting?

like image 608
Pilskalns Avatar asked Dec 04 '25 11:12

Pilskalns


1 Answers

If you take a look how the MultipleInstances property is defined, you'll see that it's type is not actually TaskMultipleInstancePolicy, but a generated type named MultipleInstancesEnum:

PS C:\>(New-ScheduledTaskSettingsSet |Get-Member MultipleInstances).Definition
System.Object MultipleInstances {get=[Microsoft.PowerShell.Cmdletization.GeneratedTypes.ScheduledTask.MultipleInstancesEnum]($this.PSBase.CimInstanceProperties['MultipleInstances'].Value);set=$this.PSBase.CimInstanceProperties['MultipleInstances'].Value = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.ScheduledTask.MultipleInstancesEnum]($args[0]);}

This has been filed as a bug on Microsoft Connect, upvote it if you want it changed.

The reporter also suggests a workaround to set the value to StopExisting:

$StopExisting = New-ScheduledTaskSettingsSet
$StopExisting.CimInstanceProperties['MultipleInstances'].Value=3
like image 132
Mathias R. Jessen Avatar answered Dec 07 '25 17:12

Mathias R. Jessen