I am trying to delete 100+ mailboxes from our cloud hosted Exchange server with PowerShell, but I keep getting this error:
The operation couldn't be performed because object '...' couldn't be found on '...'
The blanks are obviously an object from the array and our Exchange server. I am pulling the objects (I have tried both Email Addresses and Display Names) from a .csv file with the header 'mailbox'. I have used Disable-Mailbox and Remove-Mailbox, to no avail.
Here is my script:
Import-Csv "C:\temp\array.csv" | ForEach-Object {
Remove-Mailbox -identity $_.mailbox -confirm:$false
}
I have been Googling all day and I can't seem to find the reason why these objects, that are in fact mailboxes in our Exchange environment, can't be found.
Get-Mailbox
and pipe it into| Remove-Mailbox
. Make sure to use-Whatif
to make sure you are deleting what you intend to delete. – jriderName
,Display name
,Alias
,Distinguished name (DN)
,Canonical DN
,<domain name>\<account name>
,Email address
,GUID
,LegacyExchangeDN
,SamAccountName
,User ID or user principal name (UPN)
. What identity value are you using in the CSV fieldmailbox
? – Theo