1

I'm trying to create a PowerShell script that will open up a new email in outlook and put specific information there.

 $Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "[email protected]"
$Mail.CC = $Outlook.Session.CurrentUser.Name
$Mail.Subject = "sme subject"
$Mail.HTMLBody = "Dear Support,<br><br>" + `
                 "SOme text here (logfile attached).<br><br>" + `
                 "URL: ex. https://stackoverflow.com/<br>" + `
                 "Name of browser: ex. Edge/Chrome<br>" + `
                 "Proxy name: " + (Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').proxyServer + "<br>" + `
                 "LAN/VPN/wifi: <br>" +  Get-NetConnectionProfile | select Name, InterfaceAlias + "<br>" + `
                ## "Kind regards,<br>" + $Outlook.Session.CurrentUser.Name
$Mail.Attachments.Add($logfile)

$Mail.Display()

The email is being created and even the attachment is there, but

"LAN/VPN/wifi: <br>" +  Get-NetConnectionProfile | select Name, InterfaceAlias + "<br>" + `

this line/part is not really working and not sure why. It leaves it empty. So after the Proxy name, it will write "LAN/VPN/wifi:" and then the new lines are entered with the signature after.

Could you help me to figure out, what is exactly wrong here, why the value is not in the email body? what should I do to fix this?

1 Answer 1

1

You need to add () around your Get-NetConnectionProfile | select Name, InterfaceAlias command so that it evaluates that first, and then the result will be added to your string.

"LAN/VPN/wifi: <br>" +  (Get-NetConnectionProfile | select Name, InterfaceAlias) + "<br>" + `

I would like to also note that the output may not be what you were hoping for, since that will end up with something like:

LAN/VPN/wifi: <br> @{Name=Domain.com; InterfaceAlias=Ethernet 1}<br>

If you want it to look nice convert it to a HTML fragment to get a nice table in the email with your network connections:

"LAN/VPN/wifi: <br>" +  (Get-NetConnectionProfile | select Name, InterfaceAlias | ConvertTo-Html -Fragment) + "<br>" + `
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.