Get Service Name in HTML Report

Anand Shah

I am developing a simple solution which needs to send an email alert if any service is stopped on my remote server.

Below is the flow:

  1. In a notepad file write all services I want to monitor
  2. A PowerShell script will read all services from the file and will check its status.
  3. If any service is stopped, it will add things to my HTML format and will send an email.

Everything is working fine as per expectation but I am getting System.ServiceProcess.ServiceController instead of the actual service name. I am printing things on the PowerShell console and there I am getting the service name.

Code:

$Services = Get-Content D:\Services.txt
foreach ($Service in $Services) {
    Write-Host "Service Name: "$Service
}

When I execute this, I am getting service name as expected.

if ($Service.Status -eq "Stopped") {
    Write-Host "Service is stopped"
    $dataRow = "<tr><td width='10%'>199.199.50.512</td><td width='10%' >$Service</td><td width='10%' align='center'>Stopped</td></tr>"
    Add-Content $ServiceReport $dataRow;
}

Here where $Service is written, I am expecing my service name but I am getting System.ServiceProcess.ServiceController in HTML report.

HTML Report:

Wrong HTML Report

Mark Wragg

You need to be specific about which property of the object you want to return. You likely want DisplayName, so do this:

$dataRow = "<tr><td width='10%'>199.199.50.512</td><td width='10%' >$($Service.displayname)</td><td width='10%' align='center'>Stopped</td></tr>" 

Note that this is surrounded in a subexpression operator $() in order to access the property of the object correctly from within a double quoted string.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get next report page via Google_Service_AnalyticsReporting_Report

From Dev

Codeception set custom html report file name

From Dev

Get the route name in a Symfony service

From Dev

Get the PID of a Windows service by the name of the service

From Dev

How to get Maven report in html format?

From Dev

PowerShell get applied windows updates HTML report

From Dev

Using HTML to reference font name in MS Access report

From Dev

How to get report_name in Qweb header in Odoo 10?

From Dev

Vb.Net Get Report Name from String

From Dev

When launching icCube report how can I get the user name

From Dev

Get report name from DataSource of subform ms access vba

From Dev

How to get current login user name in qweb report odoo

From Dev

Retrofit: How to get the name of the called service method?

From Java

Is it possible to get service by module name in Java 9?

From Dev

Get a service container name in workflow step

From Dev

How to get FQDN DNS name of a kubernetes service?

From Dev

Get name of type in generic Angular service

From

Get domain name for service in Angular2

From Dev

AngularJS Get current factory/service name

From Dev

Get service Name of Task under aws fargate

From Dev

Angular 2 get service by string name

From Dev

Get service names depending on server name

From Dev

Java gRPC get the service name from ServerInterceptor

From Dev

get address name from WCF service

From Dev

get service name from port number

From Dev

remove the ? and name= in get method html

From Dev

HTML get name of select option

From Dev

Get the name of the parent folder in html

From Dev

NET START <SERVICE> - how/where to get the service name?

Related Related

HotTag

Archive