Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

Remotely run clean-mailboxdatabase command?

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
ablsysadmin
Asked:
ablsysadmin
1 Solution
 
Adam FarageEnterprise ArchCommented:
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
 
Abdul Khadja AlaoudineCommented:
Are you running it in Exchange Management Shell on remote server?
0
 
tshearonCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ablsysadminAuthor Commented:
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
 
tshearonCommented:
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
 
ablsysadminAuthor Commented:
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
 
tshearonCommented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now