Dear Community
I need your help with my below code.
I have a list of servers that I need to check 4 services and output result .
If the service is running it will return “ok” as a result. This works but I have a problem
capturing the error if the service fails.
I am getting below error message
Get-HypServiceStatus : Cannot bind parameter ‘ErrorAction’. Cannot convert value “hypervisor” to type “System.Management.Automation.ActionPreference”. Error: “Unable to match the
identifier name hypervisor to a valid enumerator name. Specify one of the following enumerator names and try again: SilentlyContinue, Stop, Continue, Inquire, Ignore, Suspend”
At C:\Temp\Svrsitecheck.ps1:36 char:78
- $Hypervisor = Get-HypServiceStatus -AdminAddress $Controller -ErrorAction hyp
.
The result should be something like this.
ControllerName : Controller1.exmaple.com
BrokerService : service is up and running
ConfigService : service is up and running on
HypervisorService : service is up and running on
ADIdentityService : service is up and running on
Thanks
$controllers = Get-content C:\controllers.txt foreach ($Controller in $Controllers) { $broker = Get-BrokerServiceStatus -AdminAddress $Controller -ErrorVariable broker if ($broker -eq 'ok') { $broker = "service is up and running" } else { $broker = "Service is not running on "} $config = Get-ConfigServiceStatus -AdminAddress $Controller -ErrorVariable config if ($config -eq 'ok') { $config = "service is up and running on " } else { $config = "Service is not running on "} $Hypervisor = Get-HypServiceStatus -AdminAddress $Controller -ErrorAction hypervisor if ($Hypervisor -eq 'ok') { $Hypervisor = "service is up and running on " } else { $Hypervisor = "Service is not running on"} $ADAccount = Get-AcctServiceStatus -AdminAddress $Controller -ErrorAction ADAccount if ($ADAccount -eq 'ok') { $ADAccount = "service is up and running on " } else { $ADAccount = "Service is not running on "} $status+= New-Object psobject -Property @{ControllerName = $Controller BrokerService = $broker ConfigService = $config HypervisorService = $Hypervisor ADIdentityService = $ADAccount }} $status | Select-Object ControllerName,BrokerService,ConfigService,HypervisorService,ADIdentityService