• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

GCE Agent Powershell

May 11, 2020

This is a Powershell script to restart a service if it’s down.

$ServiceName = 'GCEAgent'
$arrService = Get-Service -Name $ServiceName
 
if ($arrService.Status -ne 'Running')
{
 
    Start-Service $ServiceName
    write-host $arrService.status
    write-host 'Service starting'
    Start-Sleep -seconds 60
    $arrService.Refresh()
    if ($arrService.Status -eq 'Running')
    {
        Write-Host 'GCE Agent Service is now Running'
    }
 
}
else
{
    Write-Host 'GCE Agent Service is Running'
}

$ServiceName = 'GCEAgent' $arrService = Get-Service -Name $ServiceName if ($arrService.Status -ne 'Running') { Start-Service $ServiceName write-host $arrService.status write-host 'Service starting' Start-Sleep -seconds 60 $arrService.Refresh() if ($arrService.Status -eq 'Running') { Write-Host 'GCE Agent Service is now Running' } } else { Write-Host 'GCE Agent Service is Running' }

Filed Under: Cloud, Windows Tagged With: check, powershell, restart, service

Search This Website

Subscribe Via Email

  • Home
  • About
  • Archives

Copyright © 2023