Click here to Skip to main content
11,805,316 members (69,070 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: .NET3.5 C# .NET Server , +
Hello All,

I have a problem with Exchange server 2007. I was trying to execute the following query get-mailbox | FL. This query was working when I tried it in the Exchange server's power shell console after executing following query Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin.

But I need it to be executed from a remote machine, so I have executed it from my powershell console , as follows...

$server='';$pwd= convertto-securestring '123' -asplaintext -force;$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist 'exchangeserver\Administrator',$pwd; invoke-command -computername $server -credential $cred -scriptblock {Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin get-mailbox | FL}

But, this query fails with the following error...
A positional parameter cannot be found that accepts argument 'get-mailbox'.
  +CategoryInfo  :InvalidArgument:  {:} [Add-PSSnapin], ParameterBIndingException
  +FullyQualifiedErrorId: PositionalParameterNotFound,Microsoft.Powershell.Commands.AddPSSnapinCommand

I have modified this query again and added a ; after the snapin add section.

$server='';$pwd= convertto-securestring '123' -asplaintext -force;$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist 'exchangeserver\Administrator',$pwd; invoke-command -computername $server -credential $cred -scriptblock {Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin; get-mailbox | FL}

This is also fails with the following error.
Active Directory server exchangeserver.xxxxxx.local is not available. Error message: The supplied credential is invalid. 
     + CategoryInfo           :   NotSpecified: <0:int32> [Get-MailBox],ADOperationException
     + FullyQualifiedErrorId  :   A2B6F75B,Microsoft.Exchange.Management.RecipientTasks.GetMailbox

Then I have removed the add-snap-in section from the command and executed again.

$server='';$pwd= convertto-securestring '123' -asplaintext -force;$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist 'exchangeserver\Administrator',$pwd; invoke-command -computername $server -credential $cred -scriptblock {get-mailbox | FL}

Now it throws another error message.
The term 'get-mailbox' is not recognised as the name of a cmdlet, function, script file or operable program.
Check the spelling of the name, or if a path was included, verify that the path is corerct and try again.
     + CategoryInfo           :   ObjectNotFound: <get-mailbox:String> [],CommandNotFoundException
     + FullyQualifiedErrorId  :   CommandNotFoundException
Can someone help me on this?

Thanks in advance
Posted 14-Mar-12 18:46pm
Edited 14-Mar-12 18:49pm
Sebastian T Xavier at 19-Mar-12 1:46am
I still have the issue... Any clues would be great....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 315
1 Sergey Alexandrovich Kryukov 200
2 Richard Deeming 200
3 CPallini 160
4 CHill60 150
0 OriginalGriff 3,265
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 15 Mar 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100