View Only
  • 1.  send-mailmessage

    Posted Aug 30, 2014 04:26 PM

    in the body, how can I add text, but also add information gathered from cli.. (get-vm for example)

    This is where unix scripting seems so much easier :smileysad:

    example of what I would want in the body

    "This is a test system I tested against"

    get-vm myvm

    is it an either or? one or the other only?

    send-mailmessage -from "$smtpFrom" -to "$smtpTo" -subject "$messageSubject" -body "$body"  -smtpServer "$smtpserver"

  • 2.  RE: send-mailmessage
    Best Answer

    Posted Aug 31, 2014 07:20 AM

    You can use the PowerShell variable substitution mechanism.

    Create a string that has the info, for example

    $text = "This is the test system`r$(Get-VM -Name MyVM | Select -ExpandProperty Name)"

    Then pass the text as a value on the Body parameter.

    The `r is the NewLine and the $() construct will tell PowerShell to evaluate what is between the brackets, and use the result in that location.