Skip to content

Commit

Permalink
chore: restart stopped service script
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg3790 committed Oct 2, 2023
1 parent 7508ef4 commit 0f99998
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions PowerShell/restart_stopped_service_task.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
param (
[parameter(Mandatory=$true)]
[string]$ServiceName
)

# $ServiceName="AdobeUpdateService"

$action = New-ScheduledTaskAction -Execute "powershell" -Argument ('Invoke-Command -ScriptBlock {if ((Get-Service ' + $ServiceName + ').Status -ne \"Running\") { Start-Service ' + $ServiceName + ' }}')
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 1)
$principal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -RunLevel Highest
$task = New-ScheduledTask -Action $action -Trigger $trigger -Principal $principal

Register-ScheduledTask -TaskName AA_Test_Service -InputObject $task

0 comments on commit 0f99998

Please sign in to comment.