我嘗試使用自定義設置添加New-ScheduledTaskSettingsSet。根據Technet,MultipleInstances
可能包括StopExisting
值。Powershell新計劃任務設置集
但實際的PowerShell讓我只能選擇Parallel
,Queue
或IgnoreNew
。
爲什麼我不能使用StopExisting
?
我嘗試使用自定義設置添加New-ScheduledTaskSettingsSet。根據Technet,MultipleInstances
可能包括StopExisting
值。Powershell新計劃任務設置集
但實際的PowerShell讓我只能選擇Parallel
,Queue
或IgnoreNew
。
爲什麼我不能使用StopExisting
?
如果你看一看的MultipleInstances
屬性是如何定義的,你會看到,它的類型是不實際上TaskMultipleInstancePolicy
,但生成的類型命名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]);}
這已經提交的bug on Microsoft Connect,如果您想更改它,請立即投票。
記者還提出了一種解決方法,以將值設置爲StopExisting
:
$StopExisting = New-ScheduledTaskSettingsSet
$StopExisting.CimInstanceProperties['MultipleInstances'].Value=3
經過測試,像魅力一樣工作,謝謝!還增加了MS Connect票證。 – Pilskalns
偉大的信息,一直在敲我的頭,試圖找出我失蹤的東西。 –
如果是從截圖和你使用的是什麼操作系統。 – Matt
@Matt這是來自[TaskMultipleInstancesPolicy'枚舉的MSDN文檔](https://msdn.microsoft.com/en-us/library/microsoft.powershell.scheduledjob.taskmultipleinstancepolicy(v = vs.85)的屏幕截圖。 aspx) –