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 $().