小编Geo*_*dze的帖子

使用 PowerShell 创建 Windows 计划任务时停止现有实例选项

我正在创建一个 PowerShell 脚本,它将创建计划任务。使用 Windows GUI,在设置对话框中,我可以将其设置为“停止现有实例”,这将关闭程序(如果该程序已在运行)。通过 XML 导出此任务时,该字段标记为:

<Settings>
    <MultipleInstancesPolicy>StopExisting</MultipleInstancesPolicy>
</Settings> 
Run Code Online (Sandbox Code Playgroud)

IgnoreNew但是,在 PowerShell 中编写此内容时,我只有,Parallel和 的选项Queue。有没有办法通过 PowerShell 使用StopInstace

这是我的代码:

$Action = New-ScheduledTaskAction -Execute 'cmd.exe' -Argument "/c 'command'"

$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionDuration (New-TimeSpan -Days (365 * 20)) -RepetitionInterval  (New-TimeSpan -Minutes 33)

**$Setting = New-ScheduledTaskSettingsSet -MultipleInstances StopInstance**

Register-ScheduledTask -Action $Action -Trigger $Trigger -Setting $Setting -TaskName "Microsoft Windows > Monitoring Service" -Description "Command Runner"
Run Code Online (Sandbox Code Playgroud)

windows powershell scheduled-tasks

4
推荐指数
1
解决办法
2004
查看次数

标签 统计

powershell ×1

scheduled-tasks ×1

windows ×1