Link to home
Start Free TrialLog in
Avatar of pramod1
pramod1Flag for United States of America

asked on

outlook, powershell

I am trying to run
search-mailbox -Identity "user@domain.com" -SearchQuery subject:"credit card" -DeleteContent

but it says search-mailbox is not recognized as name of commandlet

I have outlook 2010 and running on powershell connected to office 365 user mailboxes
Avatar of Bartender_1
Bartender_1
Flag of Canada image

Hi pramod1,

Are you connecting to office 365 exchange before running this command?
See here for connecting:
https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/connect-to-exchange-online-powershell?view=exchange-ps

Also, the example provided here uses single quotes around the subject:"credit card" part of the command:
https://o365info.com/using-the-search-mailbox-powershell-command-introduction-part-1-5/

So your command would look like this:
search-mailbox -Identity "user@domain.com" -SearchQuery 'subject:"credit card"' -DeleteContent

Open in new window


Hope this helps!

Christopher.
Avatar of pramod1

ASKER

I am already connected to o365 command doesn't work
Avatar of pramod1

ASKER

I want to delete something which has come in subject from the user's mailbox, what command should I use
Avatar of pramod1

ASKER

Search-Mailbox -Identity "April Stewart" -SearchQuery 'Subject:"Your bank statement"' -DeleteContent -not working
Can you double check to ensure that your account is a member of the "Discovery Management" role? If your account is not part of this role, then the search-mailbox cmdlet is not imported. If you need to add your account to this role, you can do so through ECP, then restart your powershell session to connect with the proper credentials, and import these commands.

Hope this helps!

Christopher.
Avatar of pramod1

ASKER

where should I check, I am in exchange admin center
Avatar of pramod1

ASKER

under -permission-admin roles-discovery management?
"Exchange Admin Center"
"Permissions"
"Admin Roles"
"Discovery Management"
Edit, and make sure your account is a member.
Avatar of pramod1

ASKER

ok let me try
Avatar of pramod1

ASKER

I added myself as member but not working, do I need to connect back again
Yes, after adding yourself as a member, you must reconnect to office 365 exchange powershell, to import the missing cmdlets.

Christopher.
Avatar of pramod1

ASKER

do I need to member of any other group as it not working
Avatar of pramod1

ASKER

I am global admin also
Discovery Management is the only role you should need to add yourself to.... Are you in a hybrid environment?
To double check in your enviroment, you could run these commands:
$perms = Get-ManagementRole -Cmdlet search-mailbox

Open in new window

and
$perms | foreach {Get-ManagementRoleAssignment -role $_.name -Delegating $False |Format-Table -Auto Role,RoleAssigneeType,RoleAssigneeName}

Open in new window


It will tell you what Roles you need.
Because you're trying to delete content, with the search-mailbox command, I looked up the permissions needed for both together, this is what I found:
https://notesbytom.wordpress.com/2015/02/11/permissions-required-for-search-mailbox-and-deletecontent/

Christopher.
ASKER CERTIFIED SOLUTION
Avatar of Alexei Kuznetsov
Alexei Kuznetsov
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I guess I should've posted the information here, instead of the link.
I'll know better for next time.
Glad you've got a working solution pramod1.