exchange powershell issue

Jerry Su 201 Reputation points
2021-01-05T09:53:43.53+00:00

hello , I have a tricky issue with exchange management shell.

I have MBX1 ,MBX2, MBX3, MBX4 TOTAL 4 exchange 2016 servers.

MBX1 and MBX2 have a dag
MBX3 has all the shared mailbox so it doesn't with dag.
MBX4 has no mailbox on it, it only for the connect with exchange online (for hybrid deployment)

my laptop installed exchange management tools, and working fine (I often use my laptop to manage exchange with exchange management powershell)

today I discover I get no result when I runnging below command on my laptop.
But I get the expect result if I run the command on MBX 1 OR 2 OR 3 OR 4 (no matter which server)

Get-MailboxDatabase | Get-MailboxStatistics | Where{$_.DisconnectReason -eq "Disabled"}

anyone knows why ? thanks

Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,389 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,405 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andy David - MVP 142.7K Reputation points MVP
    2021-01-05T12:48:18.61+00:00

    This is a known issue with a few of the remote powershell commands. its looking for the -identity which is designates a mailbox rather then the database.
    ( It typically throws an error that the identity cant be found if you run your command from remote powershell)

    Running this same command on the Exchange Server directly as you have seen

    https://github.com/MicrosoftDocs/OfficeDocs-Exchange/issues/764

    The supposed way around this:

    $dbs = Get-MailboxDatabase
    $dbs | foreach {Get-MailboxStatistics -Database $_.DistinguishedName} | where {$_.DisconnectReason -eq 'Disabled'} | Format-List 
    DisplayName,MailboxGuid,LegacyDN,Database
    

    However! Im not sure that really works either. I have run this in the past and it still doesnt produce results. I think its a bug in that command when run remotely to an Exchange Server.
    If you find it still doesnt work, then run only on an Exch Server directly.
    I dont think you are doing anything wrong necessarily, its just some bugginess. ( or by design haha)


5 additional answers

Sort by: Most helpful
  1. Ashok M 6,506 Reputation points
    2021-01-05T11:18:32.453+00:00

    Hi @Jerry Su ,

    Could you please let us know the below,

    Any error message while executing that command?
    Are you using the same admin account? Have you tried with a different admin account
    Are you able to rum Get-MailboxDatabase and Get-MailboxStatistics separately

    Can you try the below,

    Launch Windows powershell using administrator
    Set-ExecutionPolicy RemoteSigned
    $UserCredential = Get-Credential (Provide the administrator credentials)
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<ServerFQDN>/PowerShell/ -Authentication Kerberos -Credential $UserCredential
    (Replace the MBX1 FQDN)
    Import-PSSession $Session -DisableNameChecking

    Then try running Get-MailboxDatabase | Get-MailboxStatistics | Where{$_.DisconnectReason -eq "Disabled"}

    If it works, try re-installing Exchange management tools on your laptop.

    If the above suggestion helps, please click on "Accept Answer" and upvote it


  2. Jerry Su 201 Reputation points
    2021-01-06T02:26:48.037+00:00

    anonymous userDavid @Rich Matheisen

    Interesting . the filter the DisconnectReasonwith not null and Disabled, and get different output

    I believe 2 command is same:

    53774-exchange-shell-3.png

    0 comments No comments

  3. Rich Matheisen 45,111 Reputation points
    2021-01-06T03:16:20.27+00:00

    Instead of importing a PowerShell session or running the command on your laptop, try running this on your laptop:

    $MyExchangeServer = (Get-ExchangeServer | Where-Object {$_.IsMailboxServer})[0]
    $d = Invoke-Command -Computer $MyExchangeServer -ScriptBlock {
                Get-MailboxDatabase | Get-MailboxStatistics | 
                    Where-Object {$_.DisconnectReason -eq "Disabled"} 
            }
    $d | FormatTable DisplayName,DisconnectReason
    

    You can eliminate the 1st line if you know the name of an Exchange server. Then just use that name instead of the "$MyExchangeServer" variable on the Invoke-Command cmdlet.


  4. Jerry Su 201 Reputation points
    2021-01-06T03:29:51.96+00:00

    halo,

    I discover if change the operator from -eq to -like, it can get the output:

    53876-exchange-shell-4.png