Search code examples
command-linepowershellvbscriptbatch-fileexchange-server-2007

How do I run a Exchange 2007 PowerShell script from the command line?


I have a very basic PowerShell script called MyScript.ps1 that runs quite happily in the Exchange Management Shell:

Get-MailboxDatabase -Status | where { $_.Mounted -eq $True }

If I try to run powershell.exe MyScript.ps1 it complains because it can't find the Get-MailboxDatabase cmdlet. I'm guessing PowerShell and the Exchange Management Shell are running slightly differently?

How do I run an Exchange-based PowerShell script from the command line?


Solution

  • You need to load the Exchange management snapin before you can run Exchange scripts from the command line. I believe the code would be like so:

    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin