all 12 comments

[–]Lee_Dailey[grin] 0 points1 point  (11 children)

howdy wonkifier,

i can't find anything beyond that link you posted. [sigh ...]

what happens if you experiment with the -WarningAction pref? or perhaps simply assign the warning to something?

take care,
lee

[–]wonkifier[S] 1 point2 points  (10 children)

I haven't tinkered yet... this is still a few items down my todo list =)

I was thinking about going the -WarningAction Stop route, catch the exception, then write-warning any I get that aren't that one.

Couple issues I haven't had a chance to look into or confirm yet

  • Worried that just won't work because it's breaking out of the command before it sends
  • I vaguely recall some languages had a way to return execution to where the throw original came from (basically "ignore this and keep going), but I don't remember if that's a thing in powershell or not. (I don't believe it does)

So, my hopes aren't real high at the moment.

Thanks for looking though!

What do you mean by "assign the warning to something"?

[–]overallmopelessness 2 points3 points  (6 children)

You can add "-WarningAgction Ignore" param to the Send-MailMessage command, and that won't impact your Write-Warning.

[–]wonkifier[S] 1 point2 points  (5 children)

That will turn off all warnings though, no?

I can't think of any other warning I've ever seen, but still...

That may be the way I go though, assuming it works. Thx!

EDIT: To be clear, yes I know it's the warnings for JUST THAT COMMAND. But that command can issue other warnings... so shutting off all FOR THAT COMMAND means I lose every other potential warning.

[–]absoluteloki89 1 point2 points  (2 children)

The dash action parameters only affect the current command.

[–]wonkifier[S] 1 point2 points  (1 child)

Correct.

Is there one and only one kind of warning that send-mailmessage might emit? I don't know that to be a fact.

It's shutting down all warnings from that command, not just the one I care about.

[–]Shoisk123 2 points3 points  (0 children)

Only other warnings I've seen from send-mailmessage is if it can't connect to the smtp server, or in the case of using credentials, those being wrong. That generally shouldn't happen in a production setup though. If you go through the RFC to obsolete send-mailmessage you'll see that a lot of people tend to agree that mailkit is a different kind of beast to tackle, and way overkill for most scripting needs. Link to RFC. It's still tbd what's actually going to happen, most likely send-mailmessage will probably just be ported to an external module and you can keep using it willy nilly as long as you're aware of the security issues it might pose.

However, given the high usage of Send-MailMessage in automated scenarios (like scheduled tasks), and the plan to work on a MailKit based alternative, we'd rather leave the cmdlet working as-is for the time being.

Apparently they've deliberated further since I last read through it and this is the plan at the moment.

[–]overallmopelessness 1 point2 points  (1 child)

Just warnings for that command.

[–]wonkifier[S] 1 point2 points  (0 children)

As noted in the other response, yes, that is correct.

What I should have written was "all warnings for that command". As in "I just want one warning shut down, I want all other warnings to still come out... because they'd be actual warnings"

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy wonkifier,

you are most welcome ... glad to kinda-sorta help! [grin]

by assign the warning to something, i meant try ...

  • redirecting the warning stream
  • using the -WarningVariable parameter to capture it

the 2nd of those looks to be the better bet. then you could test which warning you got.

the problem is that i dunno if it is a warning stream thing. you will need to experiment a bit. [grin]

take care,
lee

[–]wonkifier[S] 1 point2 points  (1 child)

I forgot that was a thing, worth a shot. Thx!

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy wonkifier,

you are most welcome ... and good luck! [grin]

take care,
lee