Member value not passed to output

Welcome Forums General PowerShell Q&A Member value not passed to output

This topic contains 1 reply, has 2 voices, and was last updated by

4 years, 3 months ago.

  • Author
  • #20191

    Points: 1
    Rank: Member


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

        [Parameter(Position=0, Mandatory=$True)]
    $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 $().

  • #20195

    Points: 0
    Rank: Member

    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,

The topic ‘Member value not passed to output’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort