Peter Filbin
Peter Filbin

Reputation: 1

Powershell command to delete 2000+ same day calendar entries in Office 365?

The title says it all. One of our executives has 2000+ series of the same exact meeting happening every single monday. How that even happens? I have no idea.

I've tried running the following:

Get-Mailbox -ResultSize unlimited | Search-Mailbox -TargetMailbox: "Email of User" -SearchQuery subject:"Subject of Calendar Entry" TargetFolder "Calendar" -DeleteContent

But I keep getting the following error:

A positional parameter cannot be found that accepts argument 'Calendar'. + CategoryInfo : InvalidArgument: (:) [Search-Mailbox], Parameter BindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Search-Mailbox Invoke-Command : Cannot write input as there are no more running pipelines At C:\Users\administrator\AppData\Local\Temp\tmp_043dc405-8409-4b6a-aa5b-a8eaa5b24cba _gjq20aee.wv2\tmp_043dc405-8409-4b6a-aa5b-a8eaa5b24cba_gjq20aee.wv2.psm1:39681 char:29 + $scriptCmd = { & <<<< $script:InvokeCommand ` + CategoryInfo : InvalidOperation: (:) [Invoke-Command], PSInvali dOperationException + FullyQualifiedErrorId : NoMoreInputWrite,Microsoft.PowerShell.Commands.I
nvokeCommandCommand

Upvotes: 0

Views: 6637

Answers (1)

SCB
SCB

Reputation: 3084

You're piping the Get-Mailbox into the Search-Mailbox which means all mailboxes in the organization are going to be searched, instead of just your executive's.

The -TargetMailbox and -TargetFolder (which does indeed need a dash) are used to send search results to a folder within a mailbox, not specify the mailbox being searched.

Try this instead:

Search-Mailbox -Identity "Executive Name" -SearchQuery 'Subject:"Subject of calendar entry"' -DeleteContent

If you just want to find out how many items there are (max 10,000) and send the results to a mailbox you can do this:

Search-Mailbox -Identity "Executive Name" -SearchQuery 'Subject:"Subject of calendar entry"' -TargetMailbox "some.mailbox" -TargetFolder "Some Folder" -LogOnly -LogLevel Full

More info https://technet.microsoft.com/en-us/library/dd298173(v=exchg.150).aspx

Upvotes: 1

Related Questions