Member value not passed to output

Hello

I have a problem with outputting one kind of variable while others work fine.

param(
    [Parameter(Position=0, Mandatory=$True)]
    [ValidateNotNullOrEmpty()]
    [string]$Name
)
$Crnt_Svc = Get-Service "*$Name*"
$Output = ($Crnt_Svc | Format-Table -AutoSize | Out-String)
$NewLine = [Environment]::NewLine

Send-MailMessage -To $Address -From "from@domain.tld" -SmtpServer $SMTPSrv -Subject "$Crnt_Svc.Name ei töötanud, üritasin käivitada." -Encoding "UTF8" -Body $Output
Write-EventLog -LogName $EventLogName -Source $EventSrc -EventId 0 -Category 0 -EntryType Error -Message "[TEST]$NewLine$Crnt_Svc.Name teenus ei töötanud. Teenus üritati käivitada. E-mail saadeti aadressaadile.$NewLine$Output"

Now, while $Output gets passed on just fine, $Crnt_Svc.Name is sent as follows: System.ServiceProcess.ServiceController.Name

So what I get via e-mail and in Event Log is:
E-mail: System.ServiceProcess.ServiceController.Name did not work, attempted to start
EventLog: [TEST]System.ServiceProcess.ServiceController.Name did not work. Attempted to start service. E-mail was set to recepient.
Status Name DisplayName


Stopped | MyServiceName | Longer name of my service

nvmd… found out that I need to put $Crnt_Svc.Name in $().

Ramil,
I’m away from my test environment, so this is just a suggestion to try. Write the subject parameter’s argument as:
“$($Crnt_Svc.Name) ei töötanud, üritasin käivitada.”

This utilizes a sub expression to first pull the value that you are looking for and placing it in the string.

Let me know if this works,
Jason