我想創建一個Windows計劃任務,使用PowerShell在任何用戶的登錄時運行.exe,然後每分鐘重新運行它並讓它每分鐘運行一次。PowerShell計劃任務
$computer = $env:ComputerName
$taskName = "MyTask"
$L = New-ScheduledTaskAction –Execute "PowerShell.exe" -Argument "$dropboxPath\request\Scripts\File_Permissions.ps1"
$T = New-ScheduledTaskTrigger -AtLogOn
$P = New-ScheduledTaskPrincipal -UserId "$env:ComputerName\$adminname" -LogonType Password -RunLevel Highest
$S = New-ScheduledTaskSettingsSet
Register-ScheduledTask -TaskName $taskName -Action $L -Trigger $T -User $adminname -Password $adminpassword -Settings $S
$T.RepetitionInterval = (New-TimeSpan -Minutes 1)
$T.RepetitionDuration = ([timespan]::MaxValue)
Set-ScheduledTask $taskName -Trigger $T
我的腳本給出了一個錯誤,它不喜歡RepetitionInterval和RepetitionDuration。
在互聯網上尋找年齡,找不到這項工作。這裏的另一個嘗試也失敗:
$computer = $env:ComputerName
$L = New-ScheduledTaskAction –Execute "PowerShell.exe" -Argument "$dropboxPath\request\Scripts\File_Permissions.ps1"
$T = @()
$T += New-ScheduledTaskTrigger -AtLogOn -User *
$T += New-ScheduledTaskTrigger -AtLogOn -RepetitionInterval (New-TimeSpan -Minutes 1) -RepetitionDuration ([timespan]::MaxValue)
$P = New-ScheduledTaskPrincipal -UserId "$env:ComputerName\$adminname" -LogonType Password -RunLevel Highest
$S = New-ScheduledTaskSettingsSet
Register-ScheduledTask -TaskName "MyTask" -Action $L -Trigger $T -User $adminname -Password $adminpassword -Settings $S
請後確切的錯誤信息 –