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

x
?
Solved

get-mailbox delete content in specific OU or distribution list

Posted on 2013-10-28
13
Medium Priority
?
1,599 Views
Last Modified: 2013-10-31
hello, i am trying to delete content from multiple users mailbox.

The command i am using does so successfully for one user, however i am looking to target a specific user base and particular subject either inside an OU or inside a distribution list. So far the script i am using doesnt work. Can anyone help?

Get-Mailbox -OrganizationalUnit "ou=local" –ResultSize unlimited | Search-Mailbox -SearchQuery 'subject:*subject*' –DeleteContent
 

(assume the OU path is accurate)

thanks in advance
0
Comment
Question by:mrbayIt
[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
  • 7
  • 6
13 Comments
 
LVL 5

Expert Comment

by:Recept
ID: 39607578
When specifying the OU use the full path including domain name.

For example;
Get-Mailbox -OrganizationalUnit 'domain.com/OU' –ResultSize unlimited | Search-Mailbox -SearchQuery 'subject:*subject*' –DeleteContent


If this still doesn't work please post the error message.
0
 

Author Comment

by:mrbayIt
ID: 39607633
thank you i tried the full path before and it didnt work, by full path do you mean

ou=etc,ou=etc,dc=domain,dc=local
0
 
LVL 5

Expert Comment

by:Recept
ID: 39607785
That is correct, either should work

Get-Mailbox -OrganizationalUnit 'domain.local/etc/etc' –ResultSize unlimited | Search-Mailbox -SearchQuery 'subject:*subject*' –DeleteContent

Get-Mailbox -OrganizationalUnit 'ou=etc,ou=etc,dc=domain,dc=local' –ResultSize unlimited | Search-Mailbox -SearchQuery 'subject:*subject*' –DeleteContent


I'd suggest you run just the Get-Mailbox command first to make sure it is working, once confirmed you can add the Search-Mailbox.

Get-Mailbox -OrganizationalUnit 'domain.local/etc/etc' –ResultSize unlimited

OR

Get-Mailbox -OrganizationalUnit 'ou=etc,ou=etc,dc=domain,dc=local' –ResultSize unlimited
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:mrbayIt
ID: 39607787
it looked like it was going to work then got an

"unexpected error a watson event has been generated"

Object reference not set to an instance of an object
0
 
LVL 5

Expert Comment

by:Recept
ID: 39607850
That sounds like an error outside of Exchange Management Shell. Did you receive it running just the Get-Mailbox command or the full thing?

Perhaps try with a smaller -ResultSize as a test.

Get-Mailbox -OrganizationalUnit 'domain.local/etc/etc' –ResultSize 10
0
 

Author Comment

by:mrbayIt
ID: 39607856
interesting i cant go above 30, but the number of people in the OU is 50 so i need to process more than that. Any idea why?
0
 
LVL 5

Expert Comment

by:Recept
ID: 39610365
It's not clear why the Exchange Management Shell is crashing, it certainly should be able to handle many more than 30 results. Do you have another machine with the Exchange Management Shell installed?

To workaround the issue you could filter the results based on name so you're dealing with smaller number of users.

Get-Mailbox -OrganizationalUnit 'domain.local/etc/etc' –ResultSize Unlimited -Filter {(name -gt 'a') -and (name -lt 'f')}

Get-Mailbox -OrganizationalUnit 'domain.local/etc/etc' –ResultSize Unlimited -Filter {(name -gt 'g') -and (name -lt 'r')}

Get-Mailbox -OrganizationalUnit 'domain.local/etc/etc' –ResultSize Unlimited -Filter {(name -gt 's') -and (name -lt 'z')}

Open in new window


If that works then try and add the second part of the command back into the mix.

Get-Mailbox -OrganizationalUnit 'domain.local/etc/etc' –ResultSize Unlimited -Filter {(name -gt 'a') -and (name -lt 'f')} | Search-Mailbox -SearchQuery 'subject:*subject*' –DeleteContent

Get-Mailbox -OrganizationalUnit 'domain.local/etc/etc' –ResultSize Unlimited -Filter {(name -gt 'g') -and (name -lt 'r')} | Search-Mailbox -SearchQuery 'subject:*subject*' –DeleteContent

Get-Mailbox -OrganizationalUnit 'domain.local/etc/etc' –ResultSize Unlimited -Filter {(name -gt 's') -and (name -lt 'z')} | Search-Mailbox -SearchQuery 'subject:*subject*' –DeleteContent

Open in new window

0
 

Author Comment

by:mrbayIt
ID: 39610475
i like that approach alot, however tried it and got

the command got positional parameter cannot be found that accepts argument filter
0
 

Author Comment

by:mrbayIt
ID: 39610492
oh you know what im sorry it did work, i tried to apply it on a different filter. Instead of OU's im doing distriibution list which gave me a better view of what i was looking for. I assumed i could apply the same path to that parameter but i guess i cant. Here is the string i am trying now

Get-Distributiongroupmember alias –ResultSize unlimited -Filter {(name -gt 'a') -and (name -lt 'f')} | Search-Mailbox -SearchQuery 'subject:subject' –DeleteContent
0
 
LVL 5

Expert Comment

by:Recept
ID: 39610518
Does the Get-DistributionGroupMember return all of the users or bomb out at 30 results as well?

Get-Distributiongroupmember alias –ResultSize unlimited
0
 

Author Comment

by:mrbayIt
ID: 39610540
it bombs out just l like the other one, and only works at 40. However your idea for doing it by name group is perfect only problem is the error i mentioned above that i get, parameter one
i should note im on exchange 2010 with latest sp and rolup
0
 
LVL 5

Accepted Solution

by:
Recept earned 2000 total points
ID: 39610609
I fear it will bomb out but can you try;

Get-Distributiongroupmember alias –ResultSize unlimited | Select-Object -First 30

Get-Distributiongroupmember alias –ResultSize unlimited | Select-Object -Last 20

Open in new window


Does this give you the 50 members your after?
0
 

Author Closing Comment

by:mrbayIt
ID: 39613733
thank you so much
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
One-stop solution for Exchange Administrators to address all MS Exchange Server issues, which is known by the name of Stellar Exchange Toolkit.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

704 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