1 Star 0 Fork 52

skybob / kasini3000

forked from chuanjiao10 / kasini3000 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
u库定时任务_建立任务计划_win.ps1 2.15 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 | Set-ScheduledTask -User "${env:COMPUTERNAME}\${env:USERNAME}" -Password $cred.GetNetworkCredential().Password
}
PowerShell
1
https://gitee.com/skybob8478/kasini3000.git
git@gitee.com:skybob8478/kasini3000.git
skybob8478
kasini3000
kasini3000
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891