If you’re in the normal non-Exchange PowerShell or PowerShell ISE and try to run Exchange cmdlet you get the following error:
+ Get-Mailbox <<<<
+ CategoryInfo : ObjectNotFound: (Get-Mailbox:String) [], Command
NotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Simple solution:
For Exchange 2010, run:
Add-PSSnapIn Microsoft.Exchange.Management.PowerShell.E2010
For Exchange 2007, run:
Add-PSSnapIn Microsoft.Exchange.Management.PowerShell.Admin
More info:
You could also enter the following to get a list of Powershell Snap-Ins that are registered on the system and that you could use:
Get-PSSnapIn -Registered
Also, when the Exchange Management Shell is started from the startmenu, it actually runs a PowerShell script which does a lot more than the above:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command “. ‘C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1’; Connect-ExchangeServer -auto”
So if you’re missing something when running the simple solution above, try running this ps1 script.
Oh and maybe you’re doing a PowerShell script and need to add the PSSnapIn? Well, if you try to add it several times, you get an annoying errormessage. You could then check if it already has been added or not:
if ( (Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin Microsoft.Exchange.Management.PowerShell.E2010
}
If you get tired of adding this SnapIn every time you start Powershell, I suggest you read about_Profiles.