none
Warning when using exchange snap-in in PowerShell RRS feed

  • Question

  • When I run PowerShell scripts for creating and modifying users to Enable-Mailbox or Disable-Mailbox, the first time the script is run I get a warning shown below.  I believe that error does not always happen the next time.  Here is the relevant parts of the code I believe:

    Function Load-PSSnapin { 
    # ----------------------------------------------------------------------------------------------
    # Function to load Exchange Snap-In(s) into PowerShell
    #  - Checks to see if the snap-in is already loaded
    #  - Checks to see if the snap-in is available to be imported
    #  - Adds snap-in to PowerShell
    # ----------------------------------------------------------------------------------------------
        Param( [parameter(Mandatory=$true)][string]$Name ) 
        
        if( -Not( Get-PSSnapin -Name $Name -ErrorAction:SilentlyContinue ) ) { 
            if( Get-PSSnapin -Registered | Where-Object { $_.Name -eq $Name } ) { 
                # Snap-in is available, but not loaded; Add the snap-in
                Add-PSSnapin -Name $Name 
            } else { 
                # Module not available on the computer
                Write-Host -ForegroundColor Red "ERROR: The specified snap-in '$name' is not found on this computer."
                break
            } # End if
        } else { 
            # Module is already loaded
        } # End if
        
    } # End Function Load-Module 
    
    
    <...other stuff...>
    
    
            # Get the user's current information
            $user = Get-ADUser $Change -Properties * -Server $Server
    
            # Remove email from account
            if( $user.mail.Length -gt 0 ) {
                # Load the Microsoft Exchange Admin Snap-In
                Load-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010 
                Disable-Mailbox -Identity $user.SamAccountName -DomainController $Server -Confirm:$false
            }
    

    I get the following output but it DOES enable or disable the user but gives this big'ol'warning:

    WARNING: The cmdlet extension agent with the index 0 has thrown an exception in OnComplete(). The exception is:
    System.InvalidOperationException: Operation is not valid due to the current state of the object.
       at Microsoft.Exchange.Data.Storage.ExchangePrincipal.get_ServerFullyQualifiedDomainName()
       at Microsoft.Exchange.Data.Storage.MailboxSession.Initialize(MapiStore linkedStore, LogonType logonType,
    ExchangePrincipal owner, DelegateLogonUser delegateUser, Object identity, OpenMailboxSessionFlags flags,
    GenericIdentity auxiliaryIdentity)
       at Microsoft.Exchange.Data.Storage.MailboxSession.<>c__DisplayClass12.<CreateMailboxSession>b__10(MailboxSession
    mailboxSession)
       at Microsoft.Exchange.Data.Storage.MailboxSession.InternalCreateMailboxSession(LogonType logonType,
    ExchangePrincipal owner, CultureInfo cultureInfo, String clientInfoString, IAccountingObject budget, Action`1
    initializeMailboxSession, InitializeMailboxSessionFailure initializeMailboxSessionFailure)
       at Microsoft.Exchange.Data.Storage.MailboxSession.CreateMailboxSession(LogonType logonType, ExchangePrincipal owner,
     DelegateLogonUser delegateUser, Object identity, OpenMailboxSessionFlags flags, CultureInfo cultureInfo, String
    clientInfoString, PropertyDefinition[] mailboxProperties, IList`1 foldersToInit, GenericIdentity auxiliaryIdentity,
    IAccountingObject budget)
       at Microsoft.Exchange.Data.Storage.MailboxSession.ConfigurableOpen(ExchangePrincipal mailbox, MailboxAccessInfo
    accessInfo, CultureInfo cultureInfo, String clientInfoString, LogonType logonType, PropertyDefinition[]
    mailboxProperties, InitializationFlags initFlags, IList`1 foldersToInit, IAccountingObject budget)
       at Microsoft.Exchange.Data.Storage.MailboxSession.OpenAsSystemService(ExchangePrincipal mailboxOwner, CultureInfo
    cultureInfo, String clientInfoString)
       at Microsoft.Exchange.ProvisioningAgent.MailboxLoggerFactory.XsoMailer.Log(AdminLogMessageData data,
    LogMessageDelegate logMessage)
       at Microsoft.Exchange.ProvisioningAgent.AdminLogProvisioningHandler.OnComplete(Boolean succeeded, Exception e)
       at Microsoft.Exchange.Provisioning.ProvisioningLayer.OnComplete(Task task, Boolean succeeded, Exception exception)
    PS D:\PowerShell\Development>

    I do NOT get this if I use the EMS directly and not just load the snappin with my script.  Is there a different way to load it to make it function properly?


    Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

    Friday, March 21, 2014 1:44 PM

Answers

  • That explains it.  You cannot run Exchange that way.  It requires remoting.  You must remote into exchange.

    $session=New-PSSession `
         -ConfigurationName Microsoft.Exchange `
         -ConnectionUri http://<FQDN of Exchange 2010 server>/PowerShell/ `
         -Authentication Kerberos
    Import-PSSession $session
    
    
    
    http://technet.microsoft.com/en-us/library/dd297932(v=exchg.141).aspx


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, March 21, 2014 4:45 PM
    • Marked as answer by Chase Roth Sunday, March 23, 2014 1:10 PM
    Friday, March 21, 2014 4:45 PM
  • Try this:

    Import-PSSession $session -DisableNameChecking


    I hope this post has helped!
    powershell -encodedcommand VwByAGkAdABlAC0ASABvAHMAdAAgAHAAbwB3AGUAcgBzAGgAZQBsAGwAQABuAG8AbABpAG0AaQB0AC4AdABvACAALQBmAG8AcgBlAGcAcgBvAHUAbgBkAGMAbwBsAG8AcgAgAGcAcgBlAGUAbgA=

    • Marked as answer by Chase Roth Sunday, March 23, 2014 1:13 PM
    Friday, March 21, 2014 8:41 PM
  • Try this:

    Import-PSSession $session -DisableNameChecking

    This also worked and is not changing anything script wide.  Thanks!  I will use this one in conjunction with the Out-Null.

    $session = New-PSSession `
    -ConfigurationName Microsoft.Exchange `
    -ConnectionUri http://server.domain.com/PowerShell/ `
    -Authentication Kerberos
    Import-PSSession $session -DisableNameChecking | Out-Null

    Thanks for the suggestion!  I am going to use this one.


    Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.


    • Edited by Chase Roth Sunday, March 23, 2014 1:07 PM
    • Marked as answer by Chase Roth Sunday, March 23, 2014 1:13 PM
    Sunday, March 23, 2014 1:07 PM

All replies

  • What version of PowerShell?  What version of Exchange?


    ¯\_(ツ)_/¯

    Friday, March 21, 2014 2:07 PM
  • [PS] C:\Windows\system32>Get-ExchangeServer | fl Name, Edition, AdminDisplayVersion
    
    Name                : BASD-MAIL01
    Edition             : Enterprise
    AdminDisplayVersion : Version 14.2 (Build 247.5)
    
    [PS] C:\Windows\system32>
    
    PS D:\PowerShell\Development> $PSVersionTable
    
    Name                           Value
    ----                           -----
    WSManStackVersion              3.0
    PSCompatibleVersions           {1.0, 2.0, 3.0}
    SerializationVersion           1.1.0.1
    BuildVersion                   6.2.9200.16398
    PSVersion                      3.0
    CLRVersion                     4.0.30319.1022
    PSRemotingProtocolVersion      2.2
    
    
    PS D:\PowerShell\Development>



    Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

    Friday, March 21, 2014 2:23 PM
  • If you are running this on the Exchange server then you needto start PowerSHell correctly:

    powershell -version 2

    Exchange is not compatible with version 3.  Read the installation notes for version to see the warnings about Exchange.

    http://www.microsoft.com/en-us/download/details.aspx?id=34595

    Read the System Requirements section very carefully.


    ¯\_(ツ)_/¯

    Friday, March 21, 2014 2:52 PM
  • Ok, so I tried running it in version 2 using the following and I still got the Warning:

    PS D:\PowerShell\Development> $PSVersionTable
    
    Name                           Value
    ----                           -----
    CLRVersion                     2.0.50727.5477
    BuildVersion                   6.1.7601.17514
    PSVersion                      2.0
    WSManStackVersion              2.0
    PSCompatibleVersions           {1.0, 2.0}
    SerializationVersion           1.1.0.1
    PSRemotingProtocolVersion      2.1
    
    
    PS D:\PowerShell\Development>
    


    For sake of testing, I opened the EMS and ran the commands.  I did NOT receive the Warning.  However, I was running PowerShell 3.0 in the EMS (see below).  It seems as though I am just running it wrong when I load it or something.

    [PS] D:\PowerShell\Development>$PSVersionTable
    
    Name                           Value
    ----                           -----
    WSManStackVersion              3.0
    PSCompatibleVersions           {1.0, 2.0, 3.0}
    SerializationVersion           1.1.0.1
    BuildVersion                   6.2.9200.16398
    PSVersion                      3.0
    CLRVersion                     4.0.30319.1022
    PSRemotingProtocolVersion      2.2
    

    Some additional information, I am doing this from a Windows 7 x64 machine with RSAT and Exchange console/shell installed.  Any other suggestions?


    Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

    Friday, March 21, 2014 4:35 PM
  • That explains it.  You cannot run Exchange that way.  It requires remoting.  You must remote into exchange.

    $session=New-PSSession `
         -ConfigurationName Microsoft.Exchange `
         -ConnectionUri http://<FQDN of Exchange 2010 server>/PowerShell/ `
         -Authentication Kerberos
    Import-PSSession $session
    
    
    
    http://technet.microsoft.com/en-us/library/dd297932(v=exchg.141).aspx


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, March 21, 2014 4:45 PM
    • Marked as answer by Chase Roth Sunday, March 23, 2014 1:10 PM
    Friday, March 21, 2014 4:45 PM
  • So then would my code be edited to look this below? Does it just then allow me to run commands I would in the EMS directly?

    # Get the user's current information $user = Get-ADUser $Change -Properties * -Server $Server # Remove email from account if( $user.mail.Length -gt 0 ) { # Remote to the Microsoft Exchange Management Shell $session=New-PSSession ` -ConfigurationName Microsoft.Exchange ` -ConnectionUri http://exchangesrv.domain.com/PowerShell/ ` -Authentication Kerberos Import-PSSession $session

    # Remove the AD user's email account Disable-Mailbox -Identity $user.SamAccountName -DomainController $Server -Confirm:$false }



    Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.


    • Edited by Chase Roth Friday, March 21, 2014 5:57 PM formatting issue
    Friday, March 21, 2014 5:55 PM
  • Ok so we are almost there.  Using the remoting as you described and I typed it seems as though the commands won't give me those issues.  I do however have another question.  How to do now get it to stop giving a warning when importing the session. 

    When I use Import-PSSession I get the following and since I am running this in a script which I output information to the console window this message gets in the way and breaks things up.

    PS D:\PowerShell> $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://server.domain.com/PowerShell/ -Authentication Kerberos
    PS D:\PowerShell> Import-PSSession $session -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
    WARNING: The names of some imported commands from the module 'tmp_yfzgmzcz.nsl' include unapproved verbs that might
    make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the
    Verbose parameter. For a list of approved verbs, type Get-Verb.
    
    ModuleType Name                                ExportedCommands
    ---------- ----                                ----------------
    Script     tmp_yfzgmzcz.nsl                    {Add-ADPermission, Add-AvailabilityAddressSpace, Add-ContentFilterPhr...
    
    
    PS D:\PowerShell> 

    I tried putting the output to Out-Null and got:

    PS D:\PowerShell> $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://server.domain.com/PowerShell/ -Authentication Kerberos
    PS D:\PowerShell> Import-PSSession $session | Out-Null
    WARNING: The names of some imported commands from the module 'tmp_krtpbigt.c5g' include unapproved verbs that might
    make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the
    Verbose parameter. For a list of approved verbs, type Get-Verb.
    PS D:\PowerShell> 

    I tried doing a Try and Catch as well and that did not suppress the warning.  Hope someone can help me make this SILENT.

    PS D:\PowerShell> $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://server.domain.com/PowerShell/ -Authentication Kerberos
    PS D:\PowerShell> Try { Import-PSSession $session | Out-Null }
    >> Catch { <# cath all #> }
    >>
    WARNING: The names of some imported commands from the module 'tmp_r3krp1an.sai' include unapproved verbs that might
    make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the
    Verbose parameter. For a list of approved verbs, type Get-Verb.
    PS D:\PowerShell> 

    Help!  Thanks!


    Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

    Friday, March 21, 2014 7:59 PM
  • Read the message. It's a warning that some of the Exchange cmdlets don't use approved verb names and is not really an error at all. You can ignore it.

    -- Bill Stewart [Bill_Stewart]

    Friday, March 21, 2014 8:08 PM
    Moderator
  • I am aware of that.  I read the warning and have mentioned I want to suppress the warning.  I am doing "Write-Host" commands to format output to the user and provide feedback as to what the script is doing.  I big yellow warning in the middle of the host output is highly undesirable.  It ruins my entire screen output format.

    Therefore I ask again, as I have tried a number of ways to suppress the "warning" as shown above.  How else could I do this?


    Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

    Friday, March 21, 2014 8:12 PM
  • What are the number of ways you have tried?

    -- Bill Stewart [Bill_Stewart]

    Friday, March 21, 2014 8:21 PM
    Moderator
  • I am not sure if you're serious or what...the examples are in the code right there in the posts.  I am just looking for assistance.  I am not all that knowledgeable beyond the "simple stuff" which is why when the simple stuff isn't working I come ask for help.

    These are in the posts above in this thread...

    1. Out-Null
    2. WarningAction SilentlyContinue
    3. ErrorAction SilentlyContinue
    4. Try { } Catch { }

    Hopefully one of you can give me another way to suppress the:

    WARNING: The names of some imported commands from the module 'tmp_krtpbigt.c5g' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.

    The Out-Null gets rid of the "ModuleType, Name, ExportedCommands" headings, but the warning remains.


    Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

    Friday, March 21, 2014 8:29 PM
  • Have you tried changing the $WarningActionPreference variable to SilentlyContinue before running your script?


    -- Bill Stewart [Bill_Stewart]

    Friday, March 21, 2014 8:37 PM
    Moderator
  • Try this:

    Import-PSSession $session -DisableNameChecking


    I hope this post has helped!
    powershell -encodedcommand VwByAGkAdABlAC0ASABvAHMAdAAgAHAAbwB3AGUAcgBzAGgAZQBsAGwAQABuAG8AbABpAG0AaQB0AC4AdABvACAALQBmAG8AcgBlAGcAcgBvAHUAbgBkAGMAbwBsAG8AcgAgAGcAcgBlAGUAbgA=

    • Marked as answer by Chase Roth Sunday, March 23, 2014 1:13 PM
    Friday, March 21, 2014 8:41 PM
  • Have you tried changing the $WarningActionPreference variable to SilentlyContinue before running your script?


    -- Bill Stewart [Bill_Stewart]

    No I had not tried changing that variable itself, I had tried just changing the "-WarningAction" to SilentlyContinue" via the command itself.  BTW I couldn't find $WarningActionPreference, but I did find $WarningPreference as a variable. 

    Changing $WarningPreference = "SilentlyContinue" did suppress the Warning and used in conjunction with the Out-Null is is now totally silent.  So I did the following and it worked:

    $WarningPreference = "SilentlyContinue"
    $session = New-PSSession `
    -ConfigurationName Microsoft.Exchange `
    -ConnectionUri http://server.domain.com/PowerShell/ `
    -Authentication Kerberos
    Import-PSSession $session | Out-Null

    Can anyone explain why changing the $WarningPreference to "SilentlyContinue" DOES work, but running "Import-PSSession $session -WarningAction SilentlyContinue" does NOT?  Is my command not typed properly?


    Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.

    Sunday, March 23, 2014 1:03 PM
  • Try this:

    Import-PSSession $session -DisableNameChecking

    This also worked and is not changing anything script wide.  Thanks!  I will use this one in conjunction with the Out-Null.

    $session = New-PSSession `
    -ConfigurationName Microsoft.Exchange `
    -ConnectionUri http://server.domain.com/PowerShell/ `
    -Authentication Kerberos
    Import-PSSession $session -DisableNameChecking | Out-Null

    Thanks for the suggestion!  I am going to use this one.


    Find this post helpful? Does this post answer your question? Be sure to mark it appropriately to help others find answers to their searches.


    • Edited by Chase Roth Sunday, March 23, 2014 1:07 PM
    • Marked as answer by Chase Roth Sunday, March 23, 2014 1:13 PM
    Sunday, March 23, 2014 1:07 PM