Solved

Remotely run clean-mailboxdatabase command?

Posted on 2014-11-04
7
106 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…

706 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

19 Experts available now in Live!

Get 1:1 Help Now