header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Trapping warnings
Last Post 03 Jun 2008 09:17 PM by mhensley. 7 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
mhensleyUser is Offline
New Member
New Member
Posts:14
Avatar

--
22 Jan 2008 10:58 PM  

Does anyone know any way to trap warnings?

I have a client with a large Exchange 2007 server (>1000 mailboxes). A simple "get-mailbox" generates a lot of warnings (mostly things like "...is not valid for Alias...";). I'd like to capture those so we can have the help desk start fixing them, but I can't find a way to do it.

I/O redirection doesn't work (neither to stdlist or stderr). $warningPreference doesn't have any useful options (for this purpose).

What I'd like is -WarningVariable, but that doesn't exist.

Any ideas?

mjolnirUser is Offline
New Member
New Member
Posts:12
Avatar

--
22 Jan 2008 11:20 PM  
Have you looked at the contents of $error after running the get-mailbox command?
mjolnirUser is Offline
New Member
New Member
Posts:12
Avatar

--
22 Jan 2008 11:33 PM  

On second thoght, for what you need it might be easier to capture the session transcript (start-transcript) and then parse the information you need out of the transcript file.

mhensleyUser is Offline
New Member
New Member
Posts:14
Avatar

--
22 Jan 2008 11:44 PM  

Thanks! That's EXACTLY what I was looking for! At least until we get -WarningVariable and $warning.

 

halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:335
Avatar

--
25 Jan 2008 12:43 PM  
The $warningPreference should be "silentlycontinue". Did you try that? Have you tried setting $errorPreference as well? I don't have Exchange around to test. I'm very curious why it's doing this, that does seem horribly annoying.
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
DonJUser is Offline
PowerShell MVP
Basic Member
Basic Member
Posts:134
Avatar

--
30 Jan 2008 03:56 PM  
Unfortunately right now the BEST solution (don't laugh) is to write a custom host app, and override the implementation of WriteWarning so that it goes to a file or something, not the console. That's the only way to selectively redirect the other pipelines. You can't trap because Warnings aren't a terminating exception, and you can only trap terminating exceptions. For right now a transcript - which captures all the host output - is probably the best workaround.
- Don Jones
www.ConcentratedTech.com
Subscribe (RSS) or visit for weekly PowerShell tips and lessons
alexpavUser is Offline
New Member
New Member
Posts:1
Avatar

--
03 Jun 2008 08:50 PM  

For the specific purpose of identifying invalid Exchange 2007 recipients, you can look at the IsValid attribute. All mail recipients which generate a warning have the IsValid attribute set to False.

The following is all on one line and will generate a C:\InvalidAliasUsers.txt

 get-recipient -resultsize Unlimited | where {$_.Isvalid -ne $true} | select Name,Alias,RecipientType | export-csv C:\invalidAliasUsers.txt

-Alex

mhensleyUser is Offline
New Member
New Member
Posts:14
Avatar

--
03 Jun 2008 09:17 PM  

Thanks! That works great!

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer