Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find mailboxes in Exchange that have disabled users.

Posted on 2015-02-20
24
Medium Priority
?
1,916 Views
Last Modified: 2015-02-24
I need to find a Exchange Mangement Shell command to find all the mailboxes that have disabled users.  The only thing i have found comes up with an empty result set, that I know should have at least 1 entry.  This is what I have so far:

$mailboxlist = Get-Mailbox -ResultSize Unlimited | ? {$_.UserAccountControl -match “AccountDisabled” -and $_.isLinked -match “false” -and $_.isResource -match “false”}
0
Comment
Question by:tommy porter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 11
24 Comments
 
LVL 71

Expert Comment

by:Qlemo
ID: 40621591
Though it is no good style, it still works (for me). But you should not use -match for boolean values, it is better to write:
$mailboxlist = Get-Mailbox -ResultSize Unlimited |
  ? { $_.UserAccountControl -match “AccountDisabled” -and !$_.isLinked -and !$_.isResource }

Open in new window

0
 

Author Comment

by:tommy porter
ID: 40621859
That did not work.  All it does is CR to the next line with no output.  thanks for the attempt, though

exchange server 2010
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40621866
Of course it does "nothing". The result is in the var. Did you check the var's content?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:tommy porter
ID: 40621935
Then, I don't know where to look.  Could you elaborate?
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40621943
For testing, use
Get-Mailbox -ResultSize Unlimited |
  ? { $_.UserAccountControl -match “AccountDisabled” -and !$_.isLinked -and !$_.isResource }

Open in new window

Otherwise, $mailboxlist contains the results. You can type that in directly on the command prompt to see its value.
0
 

Author Comment

by:tommy porter
ID: 40622182
I am definitely missing something. I can't seem to get it to work.  Either i am not using it correctly or not looking in the right spot.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40622195
What does this display?
Get-Mailbox -ResultSize Unlimited | ft -a Identity, UserAccountControl, isLinked, isResource

Open in new window

0
 

Author Comment

by:tommy porter
ID: 40622199
Something similar to this.
Capture.PNG
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40622224
UserAccountControl is empty? Test
   Get-Mailbox | gm u*
it should list UserAccountControl as a property.
0
 
LVL 17

Expert Comment

by:Viral Rathod
ID: 40622725
Get-Mailbox | ?{$_.ExchangeUserAccountControl -eq 'AccountDisabled'} | ft Name,Database,ExchangeUserAccountControl |Out-File "c:\path.txt"
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 40623038
Viral,

very, very bad style to use ft | out-file. Unless for very specific cases, where formatting needs to be exactly that way.

But you are correct, that seems to have changed. In MSX 2007 UserAccountControl works. Online doc for 2010/2013 tells different, though (https://msdn.microsoft.com/de-de/library/microsoft.exchange.data.directory.management.mailbox.exchangeuseraccountcontrol(v=exchg.150).aspx).


So the correct command should be
$mailboxlist = Get-Mailbox -ResultSize Unlimited |
  ? { $_.ExchangeUserAccountControl -match “AccountDisabled” -and !$_.isLinked -and !$_.isResource }

Open in new window

1
 

Author Comment

by:tommy porter
ID: 40626538
I ran:

UserAccountControl is empty? Test
   Get-Mailbox | gm u*
it should list UserAccountControl as a property.

and Got:

TypeName: Microsoft.Exchange.Data.Directory.Management.Mailbox

Name                         MemberType Definition
----                         ---------- ----------
UMDtmfMap                    Property   Microsoft.Exchange.Data.MultiValuedProperty`1[[System.String, mscorlib, Vers...
UMEnabled                    Property   System.Boolean UMEnabled {get;}
UsageLocation                Property   Microsoft.Exchange.Data.Directory.CountryInfo UsageLocation {get;set;}
UseDatabaseQuotaDefaults     Property   System.Nullable`1[[System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutra...
UseDatabaseRetentionDefaults Property   System.Boolean UseDatabaseRetentionDefaults {get;set;}
UserCertificate              Property   Microsoft.Exchange.Data.MultiValuedProperty`1[[System.Byte[], mscorlib, Vers...
UserPrincipalName            Property   System.String UserPrincipalName {get;set;}
UserSMimeCertificate         Property   Microsoft.Exchange.Data.MultiValuedProperty`1[[System.Byte[], mscorlib, Vers...
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40626620
See code in http:#a40623038
0
 

Author Comment

by:tommy porter
ID: 40626627
that get's me:


Name                      Alias                ServerName       ProhibitSendQuota                                      
----                      -----                ----------       -----------------                                      
DiscoverySearchMailbox... DiscoverySearchMa... xxxxxxxx         50 GB (53,687,091,200 bytes)
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40626646
Sounds like a hit!
0
 

Author Comment

by:tommy porter
ID: 40626656
Ok, that really doesn't tell me what I want to know, or I am mis-interpreting the data.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40626672
Obviously the Discovery...  mailbox is the only one being disabled, not linked and not a resource?!
0
 

Author Comment

by:tommy porter
ID: 40626739
I think the issue may be that the UserAccountControl property isn't populated, how do i change that?  it would make sense that it can't find any to match ? { $_.ExchangeUserAccountControl -match “AccountDisabled" if it doesn't exist anywhere.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40626812
UserAccountControl has been populated with my Exchange. ExchangeUserAccountControl is the correct one, according to the doc. And you got one record by using it in the condition.  IMO the result shown is plausible.
0
 

Author Comment

by:tommy porter
ID: 40626827
I know that there is at least one user (not any shown) that has a disabled user account through ad but still has a mailbox.  I am using that as my baseline for my search.  Until that user pulls up in the result set, I know that I am not looking at or in the right spot or information.  

On looking at this result set, (http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_28621197.html#a40622199) it would be logical to assume that I should see that field populated, however it isn't.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40626911
Again, it is expected that ExchangeUserAccountControl is filled, so test
Get-Mailbox -ResultSize Unlimited | ft -a Identity, UserAccountControl, ExchangeUserAccountControl, isLinked, isResource

Open in new window

now. One of both columns should contain the AccountDisabled value.
0
 

Author Comment

by:tommy porter
ID: 40626917
I think we are on the same page, I don't have any values for the UserAccountContorl field.  That is where the issue lies.  Working on getting that populated.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40626924
That field does not exist for you. That is why we try to tell you to look at ExchangeUserAccountControl. Did you?
0
 

Author Comment

by:tommy porter
ID: 40629236
I get some data returned, but not what I am looking for.
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's recap what we learned from yesterday's Skyport Systems webinar.
How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
how to add IIS SMTP to handle application/Scanner relays into office 365.
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question