Check vCenter Services
A quick function which allows you to check the VMware services on your vCenter server by hooking into windows and looking at the service status, this is useful and something I have been using as part of my vCheck script for a long time but recently became useful for a colleague.
The script can be run with no credential parameter if the current user account has windows privileges on the vCenter server to read the service information.
Example
Script
function Get-VIServices ($viserver, $credential){
If ($credential){
$Services = get-wmiobject win32_service -Credential $credential -ComputerName $viserver | Where {$_.DisplayName -like "VMware*" }
} Else {
$Services = get-wmiobject win32_service -ComputerName $viserver | Where {$_.DisplayName -like "VMware*" }
}
$myCol = @()
Foreach ($service in $Services){
If ($service.StartMode -eq "Auto") {
if ($service.State -eq "Stopped") {
$MyDetails = New-Object -TypeName PSObject -Property @{
Name = $service.Displayname
State = $service.State
StartMode = $service.StartMode
Health = "Unexpected State"
}
}
}
If ($service.StartMode -eq "Auto") {
if ($service.State -eq "Running") {
$MyDetails = New-Object -TypeName PSObject -Property @{
Name = $service.Displayname
State = $service.State
StartMode = $service.StartMode
Health = "OK"
}
}
}
If ($service.StartMode -eq "Disabled"){
If ($service.State -eq "Running"){
$MyDetails = New-Object -TypeName PSObject -Property @{
Name = $service.Displayname
State = $service.State
StartMode = $service.StartMode
Health = "Unexpected State"
}
}
}
If ($service.StartMode -eq "Disabled"){
if ($service.State -eq "Stopped"){
$MyDetails = New-Object -TypeName PSObject -Property @{
Name = $service.Displayname
State = $service.State
StartMode = $service.StartMode
Health = "OK"
}
}
}
$myCol += $MyDetails
}
$myCol
}
$creds = Get-Credential
Get-VIservices -viserver 192.168.0.11 -credential $creds
vSphere 5 License Entitlement changes VMware License Advisor–Official tool











Hey Alan,
Followed your twitter link to your blog post and plan on adding your script to my current vCenter health checks. Found a few areas to spruce it up a little bit. Here ya go!
-Rich Prescott
@Arposh
function Get-VIServices ($viserver, $credential){
$Services = get-wmiobject win32_service @PSBoundParameters | Where {$_.DisplayName -like “VMware*” }
$myCol = @()
Foreach ($service in $Services){
If ($service.StartMode -eq “Auto” -AND $service.State -eq “Stopped”) -OR ($service.StartMode -eq “Disabled” -AND $service.State -eq “Running”){
$MyDetails = New-Object -TypeName PSObject -Property @{
Name = $service.Displayname
State = $service.State
StartMode = $service.StartMode
Health = “Unexpected State”
}
}
If ($service.StartMode -eq “Auto” -AND $service.State -eq “Running”) -OR ($service.StartMode -eq “Disabled” -AND $service.State -eq “Stopped”){
$MyDetails = New-Object -TypeName PSObject -Property @{
Name = $service.Displayname
State = $service.State
StartMode = $service.StartMode
Health = “OK”
}
}
$myCol += $MyDetails
}
$myCol
}
$creds = Get-Credential
Get-VIservices -viserver 192.168.0.11 -credential $creds
Nice, I always forget about -AND and -OR and I didnt even know you could do @PSBoundParameters I will need to check out what that is doing.
hi,
in the second if statement you need to check also for manual / running and manual / stopped
If (
($Service.StartMode -eq “Auto” -AND $Service.State -eq “Running”) -OR
($Service.StartMode -eq “Disabled” -AND $Service.State -eq “Stopped”) -OR
($Service.StartMode -eq “Manual” -AND $Service.State -eq “Stopped”) -OR
($Service.StartMode -eq “Manual” -AND $Service.State -eq “Running”)
) {
$MyDetails = New-Object -TypeName PSObject -Property @{
Name = $Service.DisplayName
State = $Service.State
StartMode = $Service.StartMode
Health = “OK”
}
}