Skip to content

Instantly share code, notes, and snippets.

@SamLiu79
Created January 7, 2014 09:11
Show Gist options
  • Save SamLiu79/8296755 to your computer and use it in GitHub Desktop.
Save SamLiu79/8296755 to your computer and use it in GitHub Desktop.
Quick Restart VMware vCenter Services
#SERVICE_NAME: vspherewebclientsvc
#DISPLAY_NAME: VMware vSphere Web Client
#SERVICE_NAME: vCOConfiguration
#DISPLAY_NAME: VMware vCenter Orchestrator Configuration
#SERVICE_NAME: vctomcat
#DISPLAY_NAME: VMware VirtualCenter Management Webservices
#SERVICE_NAME: vimPBSM
#DISPLAY_NAME: VMware vSphere Profile-Driven Storage Service
#SERVICE_NAME: vimQueryService
#DISPLAY_NAME: VMware vCenter Inventory Service
#SERVICE_NAME: vpxd
#DISPLAY_NAME: VMware VirtualCenter Server
#SERVICE_NAME: vCOConfiguration
#DISPLAY_NAME: VMware vCenter Orchestrator Configuration
#SERVICE_NAME: vmwarelogbrowser
#DISPLAY_NAME: VMware Log Browser
#SERVICE_NAME: ssotomcat
#DISPLAY_NAME: vCenter Single Sign On
$VCSERVER = Read-Host "VCSERVER Address"
$remote_cred = Get-Credential -Message 'Login'
# stop queue, and when start must be reversal
$SERVICES_QUEUE = @('vspherewebclientsvc', 'vctomcat', 'vpxd', 'vimQueryService', 'ssotomcat')
#Stop service
$SERVICES_QUEUE|ForEach-Object{
$service = Get-WmiObject Win32_Service -ComputerName $VCSERVER -Filter "name=""$_""" -Credential $remote_cred
Write-Host 'Stop Service' $service.Caption
if ($service.started){
$service.StopService().ReturnValue
}
while ($TRUE){
Start-Sleep -s 2
$s = Get-WmiObject Win32_Service -ComputerName $VCSERVER -Filter "name=""$_""" -Credential $remote_cred
Write-Host $s.State
if ($s.State -eq 'Stopped'){
Write-Host 'service' $service.Caption 'Stopped'
break
}
}
}
#Start service
[array]::Reverse($SERVICES_QUEUE)
$SERVICES_QUEUE|ForEach-Object{
$service = Get-WmiObject Win32_Service -ComputerName $VCSERVER -Filter "name=""$_""" -Credential $remote_cred
Write-Host 'Start Service' $service.Caption
if (!$service.started){
$service.StartService().ReturnValue
}
while ($TRUE){
Start-Sleep -s 2
$s = Get-WmiObject Win32_Service -ComputerName $VCSERVER -Filter "name=""$_""" -Credential $remote_cred
Write-Host $s.State
if ($s.State -eq 'Running'){
Write-Host 'service' $service.Caption 'Started'
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment