Author Posts

August 3, 2015 at 5:36 pm

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



August 3, 2015 at 6:11 pm

I think the first place to start is the following line:

$Hypervisor = Get-HypServiceStatus -AdminAddress $Controller -ErrorAction hypervisor

If you notice, part of the error gives you a clue as to what's wrong:

Error: "Unable to match theidentifier name hypervisor to a valid enumerator name. Specify one of the following enumerator names and try again: SilentlyContinue, Stop, Continue, Inquire, Ignore, Suspend"

When you specify the -ErrorAction parameter, the value must be one of a given set (SilentlyContinue, Stop, Continue, Inquire, Ignore, Suspend), and you are assigning the parameter the value "hypervisor" which is not part of the set.

August 3, 2015 at 7:13 pm

My bad 🙂 .. Thanks Vaskan . I was intend to use errorvariable but i end up typing erroraction and did not look in to it. 🙂 i should have strong coffee now.. 🙂 its working fine now.. thanks again for your timely response