Powershell New-ScheduledTaskSettingsSet

标签 powershell scheduled-tasks powershell-5.0

我尝试添加 New-ScheduledTaskSettingsSet带有自定义设置。根据 Technet,MultipleInstances 有可能的选项,包括 StopExisting 值。

enter image description here

但实际的 powershell 只允许我选择 ParallelQueueIgnoreNew

为什么我不能使用 StopExisting

最佳答案

如果你看一下 MultipleInstances 属性是如何定义的,你会发现它的类型实际上是 not 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

关于Powershell New-ScheduledTaskSettingsSet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33241031/

相关文章:

c# - PowerShell 使用 PSSession 删除项目

powershell - 可选字符串参数(应为 NULL)

powershell - 跨多个卷搜索文件

c# - csom 上下文凭据安全

powershell - 有没有办法在 powershell session 中启用 "noninteractive"

powershell - 如何在 PowerShell 中将分隔字符串转换为嵌套哈希表?

powershell - 如何在 get-filehash 中使用 write-progress

powershell - 将第八行和第九行添加到所有 *.txt 文件

windows - 如何在 Windows 命令提示符下每 5 分钟安排一个任务?

asp.net - 触发Web服务的第三方服务