Solved

Remotely run clean-mailboxdatabase command?

Posted on 2014-11-04
7
113 Views
Last Modified: 2015-03-10
I'm trying to remotely execute the clean-mailboxdatabase command from a remote server by using the following syntax in a .ps1 file:

$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://ServerName.domain.com/PowerShell/ -Authentication Kerberos
Import-PSSession $s
clean-mailboxdatabase -identity "ServerName\MailboxStoreName"

I call the above .ps1 file using the following batch file:
Powershell.exe -executionpolicy bypass -File  C:\CleanUpMail.ps1

The error I get is:
The operation couldn't be performed because object 'ServerName\MailboxStoreName' couldn't be found on 'DomainControllerName.Domain.Com'.
    + CategoryInfo          : NotSpecified: (0:Int32) [Clean-MailboxDatabase],
    ManagementObjectNotFoundException
    + FullyQualifiedErrorId : 2458494B,Microsoft.Exchange.Management.SystemCon
   figurationTasks.CleanMailboxDatabase

I'm not sure why it's looking for the mailbox stores on the DC. I use a similar process to issue the following syntax without issue:

$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://ServerName.domain.com/PowerShell/ -Authentication Kerberos
Import-PSSession $s
Move-ActiveMailboxDatabase 'MailboxStoreName' -ActivateOnServer TargetServer -Confirm:$false

I've tried the following combinations:
clean-mailboxdatabase -identity "ServerName\MailboxStoreName"
clean-mailboxdatabase -identity "ServerName\Master\MailboxStoreName"
clean-mailboxdatabase "MailboxStoreName"

Please advise! Exchange 2010.
0
Comment
Question by:ablsysadmin
7 Comments
 
LVL 19

Expert Comment

by:Adam Farage
ID: 40421301
From technet:

The Identity parameter specifies the mailbox database that you want to update. You can use one of the following values:

    GUID

    Distinguished name (DN)

    Name of the mailbox database


Run Get-MailboxDatabase and grab the GUID. Throw all of them into a CSV file and run Import-CSV along with the ForEach (%) switch to run against all databases.
0
 
LVL 5

Expert Comment

by:Abdul Khadja Alaoudine
ID: 40421305
Are you running it in Exchange Management Shell on remote server?
0
 
LVL 8

Expert Comment

by:tshearon
ID: 40421545
Why are you adding in all the additional work and making this so hard? Just do the following:

1. Open EMS (Exchange Management Shell) from a workstation where you have the Exchange Management Tools installed.
2. Type the following Clean-MailboxDatabase <mailboxdatabasename>

You are done.
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:ablsysadmin
ID: 40423269
Get-MailboxDatabase does not return a GUID, it returns Name, Server, Recovery, ReplicationType.

We're not running Exchange Management Shell on the remote server, but we're importing the Exchange commands into the remote powershell session using:

$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://ServerName.domain.com/PowerShell/ -Authentication Kerberos
Import-PSSession $s

Yes, Clean-MailboxDatabase <mailboxdatabasename> is easy, but running it manually on a server with Exchange Management Tools is not what we're trying to achieve here.
0
 
LVL 8

Expert Comment

by:tshearon
ID: 40423643
Why not? It is the accepted and supported way of doing it? You wouldn't want to do it any other way as it is just complicating an already easy process.
0
 

Author Comment

by:ablsysadmin
ID: 40423704
The idea is to automate it remotely as that is the requirement presented to us. We'd really just like to know if it's possible to achieve this. If it's not, we'll obviously go back to the method you described. Thank you for constant feedback.
0
 
LVL 8

Accepted Solution

by:
tshearon earned 500 total points
ID: 40423707
You can still automate it remotely but with the right tools installed on the machine. It's the best/easiest way. Good luck.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
how to add IIS SMTP to handle application/Scanner relays into office 365.
This video discusses moving either the default database or any database to a new volume.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

3 Experts available now in Live!

Get 1:1 Help Now