问题
I try to add New-ScheduledTaskSettingsSet with custom settings. As per Technet, there is possible options for MultipleInstances
and including StopExisting
value.
But actual powershell allows me choose only Parallel
, Queue
or IgnoreNew
.
Why I can't use StopExisting
?
回答1:
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
来源:https://stackoverflow.com/questions/33241031/powershell-new-scheduledtasksettingsset