passing variable to email recipient field in powershell -



passing variable to email recipient field in powershell -

i trying pass variable dropdown list email recipient. script dropdown list:

$objlistbox = new-object system.windows.forms.listbox $objlistbox.location = new-object system.drawing.size(30,90) $objlistbox.size = new-object system.drawing.size(260,20) $objlistbox.height = 80 [void] $objlistbox.items.add("rod@tafe.gov.au") [void] $objlistbox.items.add("james@msn.com") [void] $objlistbox.items.add("josh@abc.net") [void] $objlistbox.items.add("logan@cba.com") [void] $objlistbox.items.add("george@tafe.gov.nsw") [void] $objlistbox.items.add("nic@someone.com") [void] $objlistbox.items.add("shit@box.com") $ourform.controls.add($objlistbox) $ourform.topmost = $true $ourform.add_shown({$objform.activate()}) [void] $objform.showdialog() $mailto

this script send email:

send-mailmessage -to '$mailto' -from 'arivergod@msn.com' ` -body 'itisdone, sleeping fish' ` -subject 'contract' -smtp 'arivergod@msn.com'

try changing showdialog() phone call this:

if ($objform.showdialog() -eq [windows.forms.dialogresult]::ok) { $mailto = $objlistbox.selectedvalue }

also can't single quote around variable e.g. '$mailto'. single quotes in powershell verbatim strings in c#. gets passed value parameter literally $mailto. alter this:

send-mailmessage -to $mailto -from arivergod@msn.com ` -body 'itisdone, sleeping fish' ` -subject contract -smtp arivergod@msn.com

also note powershell typically process arguments strings default unless start $ @ ( , ; or {. if have spaces, embedded quotes or semicolon in string argument, need quote it.

powershell

Comments

Popular posts from this blog

c# - ASP.NET MVC Sequence contains no matching element -

java - Parsing XML, skip certain tags -

rest - How to invalidate user session on inactivity in a stateless server? -