0

I am currently working on a script that would delete meeting requests from terminated employees of the organization. I found this one as a reference (Deleting Meeting Requests made by terminated users) and i can't get it to work for me because of my error.

this is my script

Add-Type -Path "C:\Program Files (x86)\Microsoft\Exchange\Web Services\2.1\Microsoft.Exchange.WebServices.dll"


$UserCredential = Get-Credential
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $session -AllowClobber
#Enter-PSSession $session

$rooms = Get-Mailbox -RecipientTypeDetails RoomMailbox -ResultSize Unlimited  

$count=$rooms.count
$TerminatedUsers = Get-Content D:\Work\SHAR78\resignedEmployees.txt

Write-Host "count of rooms " $count

foreach ($user in $TerminatedUsers) {

   Write-Host "terminated user" $user

    foreach($room in $rooms) {

        $room | Search-Mailbox -searchquery "kind:calendar from:$($user)" -targetmailbox admin@admin.com -TargetFolder "SearchData" -logonly -loglevel full
        #-targetmailbox administrator@domain.com -targetfolder "Deleting Meeting" -deletecontent -force

    }
}

i am connected to Exchange Online so im not sure why Search-Mailbox is not being imported. my account has an Owner permission as well.

Community
  • 1
  • 1
Page F.P.T
  • 653
  • 4
  • 11
  • 24
  • Did you check out what is being imported from the session? Maybe it's not exposed which might be because you don't have sufficient permissions? – Seth May 09 '17 at 06:01
  • This cmdlet is available in on-premises Exchange Server 2016 and in the cloud-based service. So , could you please use get-command and see if it is available. – Ranadip Dutta May 09 '17 at 06:05
  • Hi @Seth what permission does my account need? i checked using get-command and i cant find search-Mailbox. i only see Search-MailboxAuditLog. – Page F.P.T May 09 '17 at 06:14
  • @RanadipDutta i used Get-Commant what i got for Search does not include Search-Mailbox. it has search-AdminAuditLog then Search-MailboxAuditLog – Page F.P.T May 09 '17 at 06:41
  • Exactly. That means you do not have the cmdlet available. This is only for exchange 2016. So you have to see some workaround for this in lower version. :) But as per my knowledge In Exchange 2010 Service Pack 1 (SP1), you can use the Search-Mailbox – Ranadip Dutta May 09 '17 at 06:43
  • I have posted and answer, you can check that . It should do your work. @PageF.P.T – Ranadip Dutta May 09 '17 at 06:47
  • @RanadipDutta thanks, may i know what is the default exchange for office 365 outlook? – Page F.P.T May 09 '17 at 06:49
  • 1
    If you buy a new Office365 service now it will be Exchange 2013 CU1 which is the latest version of Exchange that time - older Office365 organisations will be a mix of 2010 and 2013 depending on when they were purchasing. NOw i think newer versions available. Not sure exactly – Ranadip Dutta May 09 '17 at 06:53
  • 1
    According to [this](https://technet.microsoft.com/en-us/library/dd876958(v=exchg.150).aspx) you would need to be in the (default) group "Discovery Management" or "Organization Management". Alternatively you could assign the "Mailbox search" role to a custom group. – Seth May 09 '17 at 07:16

1 Answers1

1

It seems like you do not have the cmdlet available. So check the proper version.

Please do the following and see:

Create "Mailbox Import-Export Management" role group and be a member of it.

To create the role group use:

New-RoleGroup "Mailbox Import-Export Management" -Roles "Mailbox Import Export"

To add the member:
Add-RoleGroupMember "Mailbox Import-Export Management" -Member

Apart from that if you want to search then you can use like this:

Get-mailbox | Export-Mailbox –AllContentKeywords "thekeysyouwant" –TargetMailbox Administrator –TargetFolder 'foldername'

Hope it helps.

Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
  • I now get this: The term 'Export-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. – Page F.P.T May 09 '17 at 07:03
  • I believe some issue with the pssnapin of exchange. Could you please try in another box and check – Ranadip Dutta May 09 '17 at 07:37
  • Try this link. [LINK](http://www.aurelp.com/tag/solved-export-mailbox-and-import-mailbox-commands-not-recognized/) – Ranadip Dutta May 09 '17 at 12:02
  • Hello, Thank you for your help i have already resolved it although i am not really sure how i did that i'm guessing its on the permission. but thank you anyway! :) – Page F.P.T May 10 '17 at 06:38
  • @PageF.P.T: Please upvote / accept the answer if it helps you :) – Ranadip Dutta May 10 '17 at 08:38