Solved

Remotely run clean-mailboxdatabase command?

Posted on 2014-11-04
7
144 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
To show how to generate a certificate request 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 Servers >> Certificates…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Suggested Courses

617 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