Powershell New-ScheduledTaskSettingsSet

泄露秘密 提交于 2019-12-10 18:24:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!