Get-HostService
VMware: Retrieves information about a host service
#Requires -Version 5.1
#Requires -Modules VMware.VimAutomation.Core
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$VIServer,
[Parameter(Mandatory = $true)]
[pscredential]$VICredential,
[Parameter(Mandatory = $true)]
[string]$HostName,
[string]$ServiceKey,
[string]$ServiceLabel,
[switch]$Refresh
)
Process {
$vmServer = $null
try {
$vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$services = Get-VMHostService -Server $vmServer -VMHost $HostName -Refresh:$Refresh -ErrorAction Stop | Select-Object *
$output = @()
if (-not [System.String]::IsNullOrWhiteSpace($ServiceKey)) {
$output += $services | Where-Object { $_.Key -like $ServiceKey }
}
if (-not [System.String]::IsNullOrWhiteSpace($ServiceLabel)) {
$output += $services | Where-Object { $_.Label -like $ServiceLabel }
}
if ($output.Count -le 0) { $output = $services }
foreach ($item in $output) {
$item | Add-Member -NotePropertyName 'Timestamp' -NotePropertyValue $timestamp -Force
Write-Output $item
}
}
catch { throw }
finally { if ($null -ne $vmServer) { Disconnect-VIServer -Server $vmServer -Force -Confirm:$false -ErrorAction SilentlyContinue } }
}IP address or DNS name of the vSphere server
PSCredential object for authenticating with the server
Host for which to retrieve the available services
Key of the service to retrieve
Label of the service to retrieve
Off
Refresh the service information before retrieving it