Have this little function that i use everywhere… i’ve tested this code from a remote session to the server and it works but every time in run it from the api it returns the following:
OperationStopped:
Line |
9 | Send-MailMessage -SmtpServer $smtp -To $to -From $from -Subje …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Object reference not set to an instance of an object.
i’ve verified using wait-debugger that all of the variables are popultated at the time that the send-mailmessage command is issued and if i copy and paste that line of coding during a debugging session it works fine.
The code used is below:
function emailnotice($access, $userid){
$smtp = “mailservername.domain.com”
#$to = $id
$to = “recipient@domain.com”
$from = “sender@domain.com”
$subject = “New access has been granted to: $userid”
$emailbody = “Instructions for use will be provided at a later time.” + $access
Send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $emailbody
}
$id = “username”
$newAccess = “GeneratedAccess”
emailnotice $newAccess $id
Anyone have any thoughts or suggestions?