停用所有“准备/运行任务”在特定文件夹中的一堆服务器上,能够再次激活这些任务

发布于 2025-01-26 18:51:48 字数 189 浏览 3 评论 0原文

我正在寻找一个PowerShell脚本,该脚本可以禁用在3个或更多服务器上任务调度程序中特定文件夹中“准备就绪”或“运行”的所有任务。

更新软件后,我应该能够再次激活脚本被禁用的所有任务,而不仅仅是激活所有禁用的脚本,而是尤其是脚本禁用的脚本。

我知道这应该是可能的,但是我无法组装单个部分。一切都不仅仅是一个命令,都适合我的逻辑能力。

i am looking for a Powershell script that can disable all tasks that are "ready" or "running" in a specific folder in the Task Scheduler on 3 or more servers.

After we updated the software i should be able to activate all the tasks that were disabled by the script again, not just activate all disabled scripts, but specificly the ones that were disabled by the script.

I know this should be possible, but i am not capable of assembling the single parts. Everything thats more than a single command is to much for my logic capacitys.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贩梦商人 2025-02-02 18:51:48
<#getScheduledTasksinfo-FreeholdReboots.ps1
.Synopsis
   PowerShell script to list all Scheduled Tasks, the User ID and the State
.DESCRIPTION
   This script scans the content of the c:\Windows\System32\tasks and searches the UserID XML value. 
   The output of the script is a comma-separated log file containing the Computername, Task name, UserID, Status.
.Author
   UNKNOWN
.Tweaker
   Patrick Burwell
#>

Remove-Item -Force "D:\batch\Logs\Maintenance\$day-SchedTasks-Reboots.csv"
$logfilepath = "D:\batch\Logs\Maintenance\$day-SchedTasks-Reboots.csv"
$ErrorActionPreference = "SilentlyContinue"

$serverlist = gc D:\batch\input\servers.txt

foreach($server in $serverlist){
    if($server -like '#*')
    {
        continue
    }
    Write-Host $server

    $path = "\\" + $server + "\c$\Windows\System32\Tasks"
    $tasks = Get-ChildItem -Path $path -File

    if ($tasks)
    {
        Write-Verbose -Message "I found $($tasks.count) tasks for $server"
    }

    foreach ($item in $tasks)
    {
        if($item -like 'Optimize Start Menu*'){continue}
        if ($item -like "User_Feed_Synchronization*"){continue}
        if($item -like 'ComputeSensorWatchDog*'){continue}
        if ($item -like "Google*"){continue}
        $AbsolutePath = $path + "\" + $item.Name
        $task = [xml] (Get-Content $AbsolutePath)
        $states = (Get-ScheduledTask -Verbose -TaskPath '\' -TaskName "reboot")
        [STRING]$check = $task.Task.Principals.Principal.UserId
        [STRING]$state = $states.State
        if ($task.Task.Principals.Principal.UserId)
        {
        if($item -ilike "*reboot*"){
          Write-Verbose -Message "Writing the log file with values for $server"           
          Add-content -path $logfilepath -Value "$server,$item,$check,$state"
        }
        else {continue}
        }

    }
}
<#getScheduledTasksinfo-FreeholdReboots.ps1
.Synopsis
   PowerShell script to list all Scheduled Tasks, the User ID and the State
.DESCRIPTION
   This script scans the content of the c:\Windows\System32\tasks and searches the UserID XML value. 
   The output of the script is a comma-separated log file containing the Computername, Task name, UserID, Status.
.Author
   UNKNOWN
.Tweaker
   Patrick Burwell
#>

Remove-Item -Force "D:\batch\Logs\Maintenance\$day-SchedTasks-Reboots.csv"
$logfilepath = "D:\batch\Logs\Maintenance\$day-SchedTasks-Reboots.csv"
$ErrorActionPreference = "SilentlyContinue"

$serverlist = gc D:\batch\input\servers.txt

foreach($server in $serverlist){
    if($server -like '#*')
    {
        continue
    }
    Write-Host $server

    $path = "\\" + $server + "\c$\Windows\System32\Tasks"
    $tasks = Get-ChildItem -Path $path -File

    if ($tasks)
    {
        Write-Verbose -Message "I found $($tasks.count) tasks for $server"
    }

    foreach ($item in $tasks)
    {
        if($item -like 'Optimize Start Menu*'){continue}
        if ($item -like "User_Feed_Synchronization*"){continue}
        if($item -like 'ComputeSensorWatchDog*'){continue}
        if ($item -like "Google*"){continue}
        $AbsolutePath = $path + "\" + $item.Name
        $task = [xml] (Get-Content $AbsolutePath)
        $states = (Get-ScheduledTask -Verbose -TaskPath '\' -TaskName "reboot")
        [STRING]$check = $task.Task.Principals.Principal.UserId
        [STRING]$state = $states.State
        if ($task.Task.Principals.Principal.UserId)
        {
        if($item -ilike "*reboot*"){
          Write-Verbose -Message "Writing the log file with values for $server"           
          Add-content -path $logfilepath -Value "$server,$item,$check,$state"
        }
        else {continue}
        }

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文