1 Star 0 Fork 54

Ryouj/kasini3000

forked from chuanjiao10/kasini3000 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
u库定时任务_建立任务计划_win.ps1 2.20 KB
一键复制 编辑 原始数据 按行查看 历史
#建议保存编码为:bom头 + utf8
#Requires -RunAsAdministrator
$任务计划模块 = (Get-Command -Module ScheduledTasks).name
if ($任务计划模块.Length -lt 3)
{
Write-Error '错误:此版本win,缺少任务计划模块!'
exit 3
}
else
{
if (Test-Path -LiteralPath 'c:\Program Files\PowerShell\7\pwsh.exe')
{
$操作 = New-ScheduledTaskAction -Execute 'C:\Program Files\PowerShell\7\pwsh.exe' -Argument " -WindowStyle hidden -File c:\ProgramData\kasini3000\u_db_crontab.ps1" -WorkingDirectory "c:\ProgramData\kasini3000"
}
elseif (Test-Path -LiteralPath 'c:\Program Files\PowerShell\7-preview\pwsh.exe')
{
$操作 = New-ScheduledTaskAction -Execute 'c:\Program Files\PowerShell\7-preview\pwsh.exe' -Argument " -WindowStyle hidden -File c:\ProgramData\kasini3000\u_db_crontab.ps1" -WorkingDirectory "c:\ProgramData\kasini3000"
}
elseif (Test-Path -LiteralPath 'c:\Program Files\PowerShell\6\pwsh.exe')
{
$操作 = New-ScheduledTaskAction -Execute 'C:\Program Files\PowerShell\6\pwsh.exe' -Argument " -WindowStyle hidden -File c:\ProgramData\kasini3000\u_db_crontab.ps1" -WorkingDirectory "c:\ProgramData\kasini3000"
}
else
{
$操作 = New-ScheduledTaskAction -Execute 'C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe' -Argument " -WindowStyle hidden -File c:\ProgramData\kasini3000\u_db_crontab.ps1" -WorkingDirectory "c:\ProgramData\kasini3000"
}
$触发器 = New-ScheduledTaskTrigger -Daily -At 00:00:01
$设置 = New-ScheduledTaskSettingsSet -DontStopIfGoingOnBatteries -AllowStartIfOnBatteries
$cred = Get-Credential -Message '为了把卡死你3000,添加到win任务计划,请输入账户和密码'
Register-ScheduledTask `
-TaskName "卡死你3000批量运维工具" `
-User "${env:COMPUTERNAME}\${env:USERNAME}" `
-Password $cred.GetNetworkCredential().Password `
-Action $操作 `
-Trigger $触发器 `
-Settings $设置
$任务2 = Get-ScheduledTask -TaskName "卡死你3000批量运维工具"
$任务2.Triggers.Repetition.Duration = "P1D"
$任务2.Triggers.Repetition.Interval = "PT1M"
$任务2.Settings.ExecutionTimeLimit = "PT50S"
$任务2 | Set-ScheduledTask -User "${env:COMPUTERNAME}\${env:USERNAME}" -Password $cred.GetNetworkCredential().Password
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PowerShell
1
https://gitee.com/ryouj/kasini3000.git
[email protected]:ryouj/kasini3000.git
ryouj
kasini3000
kasini3000
master

搜索帮助