mrbayIt
asked on
get-mailbox delete content in specific OU or distribution list
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
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
ASKER
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
ou=etc,ou=etc,dc=domain,dc
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,d c=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,d c=local' –ResultSize unlimited
Get-Mailbox -OrganizationalUnit 'domain.local/etc/etc' –ResultSize unlimited | Search-Mailbox -SearchQuery 'subject:*subject*' –DeleteContent
Get-Mailbox -OrganizationalUnit 'ou=etc,ou=etc,dc=domain,d
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,d
ASKER
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
"unexpected error a watson event has been generated"
Object reference not set to an instance of an object
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
Perhaps try with a smaller -ResultSize as a test.
Get-Mailbox -OrganizationalUnit 'domain.local/etc/etc' –ResultSize 10
ASKER
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?
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.
If that works then try and add the second part of the command back into the mix.
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')}
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
ASKER
i like that approach alot, however tried it and got
the command got positional parameter cannot be found that accepts argument filter
the command got positional parameter cannot be found that accepts argument filter
ASKER
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-Distributiongroupmembe r alias –ResultSize unlimited -Filter {(name -gt 'a') -and (name -lt 'f')} | Search-Mailbox -SearchQuery 'subject:subject' –DeleteContent
Get-Distributiongroupmembe
Does the Get-DistributionGroupMembe r return all of the users or bomb out at 30 results as well?
Get-Distributiongroupmembe r alias –ResultSize unlimited
Get-Distributiongroupmembe
ASKER
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
i should note im on exchange 2010 with latest sp and rolup
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you so much
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.