none
Can't get "-warningvariable" working on get-mailcontact cmdlet

    Question

  • Hey,

    After migrating from Ex2003 to 2010 we have a bunch (around 20 000) mail-enabled contacts, where some of these are corrupt due to invalied aliases or whatever.

    Im trying a simple

    get-mailcontact -warningvariable ContactsWarning

    or

    get-mailcontact -warningvariable +ContactsWarning

    in the hope of gathering all contacts that give a warning to this variable and handle them from there. However, the warnings are just outputted to the console, and not stored in the var. I'm wondering if this is a bug?

    Wednesday, June 08, 2011 8:02 PM

Answers

  • Here's a workaround, ugly though it may be:

    start-transcript ./transcript.txt
    get-mailcontact
    stop-transcript
    $errors = select-string ./transcript.txt -pattern "WARNING: The object (.+) has been corrupted"
    $bad_alias = $errors |% {$_.matches[0].groups[1].value}
    $bad_alias


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Friday, June 10, 2011 7:38 PM

All replies

  • Seems to be a bug, or at least a limitation of the remoting environment.

    I just tested on my system, and from an EMS shell, $warnvariable does not get populated.  If I open up a generic PS console session and load the management snapin (yeah, I know that's not supported) it works.

    add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Wednesday, June 08, 2011 8:38 PM
  • Hi,

     

    I test this command on my Exchange 2010 SP1 to collect all the contacts, it worked.

    Could you please try this command?

    Get-MailContact –warningvariable contactswarning | Out-File C:\test.txt

    All the contacts was outputted in the .txt file.


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Friday, June 10, 2011 6:00 AM
    Moderator
  • The problem isn't with getting the contacts, it's with getting the warning messages in the $contactswarning variable.  In the remoting environment, warnings are written to the screen but not captured in the warnvariable. 
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Friday, June 10, 2011 9:18 AM
  • Here's a workaround, ugly though it may be:

    start-transcript ./transcript.txt
    get-mailcontact
    stop-transcript
    $errors = select-string ./transcript.txt -pattern "WARNING: The object (.+) has been corrupted"
    $bad_alias = $errors |% {$_.matches[0].groups[1].value}
    $bad_alias


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Friday, June 10, 2011 7:38 PM
  • Thanks, that's a valid workaround. I'll implement it.

     

    best regards,

    Trond

    Friday, August 05, 2011 9:24 AM
  • Just a small Tip,
    Use the script CheckinvalidRecipients
    Note the switches.


    [PS] C:\Program Files\Microsoft\Exchange Server\V14\scripts>get-help .\CheckInvalidRecipients.ps1
    CheckInvalidRecipients.ps1 [[-OrganizationalUnit] <String>] [[-ResultSize] <String>] [[-Filter] <String>] [[-DomainCont
    roller] <String>] [-FixErrors] [-RemoveInvalidProxies] [-ShowInvalidProxies] [-OutputObjects]


    Martina Miskovic
    Friday, August 05, 2011 10:06 AM
  • Hello,
    This is a very old topic, but I have a similar issue.
    I need to get the warning variable on my Skype cmdlet.
    You should use Invoke-Command to get warning message on your remote PowerShell cmdlet.

    # If you run:

    $null = Get-MailContact -WarningVariable WarningVariable


    $WarningVariable will be empty

    # But if you run:

    $null = Invoke-Command { Get-MailContact } -WarningVariable WarningVariable

    $WarningVariable contains the warning message

    Hope this can be useful for someone ^^

    Friday, March 17, 2017 10:58 AM