Wednesday, 9 September 2009

Connecting To Exchange 2010 Using Remote Powershell…

Remote Powershell (Windows Powershell v2) allows you to connect to an Exchange 2010 organization from a client without having the 2010 management tools installed. You should install Windows Management Framework, which includes Powershell V2 and Windows Remote Management on the client. Download it here. Make sure that you select the correct version (x86 or X64) depending on the client you use.

The clients should be either Vista SP1+ or Windows 2008 SP1+ (x86 or x64). Uninstall any previous versions of Management Framework, if you have it. Instructions are here.

In order to connect to an Exchange 2010 organization from a client with windows management framework installed and no 2010 management tools, we need to follow certain steps.

  • Store the login details of an account that has permissions to remote in. By default, the account that was used to install Exchange 2010 will have the permissions already.
  • If you want another user to be able to initiate a remote powershell session, run Set-User –identity username –RemotePowershellEnabled $True
  • Store the session details in a variable
  • Import the session defined. It will take a while.
  • Run exchange cmdlets / administer the 2010 environment.
  • Once you have finished your work, remove the session.

Let’s get to business. Once the framework is installed, launch Windows Powershell V2

Run $user = Get-Credential to store the login account details. A login box gets prompted, fill in the details and click OK. The account details are now in the variable “user”.

S1

Run $session = New-PSSession -Configurationname Microsoft.Exchange –ConnectionUri http://hew-dc/powershell -Credential $user

S2

This stores the session details including the account used for remoting.

Run Import-PSSession $session to import the server-side powershell session to the client side one.

S3

It takes some time to import the exchange cmdlets. Once it is completed, you can use all exchange cmdlets in your Windows Powershell session.

S4

Run Remove-PSSession $session once you have completed your work.

S5

That’s it for now!


7 comments:

Anonymous said...

Hi Rajith Jose Enchiparambil,

when i executed the following command

"[PS] C:\Windows\system32>$session = New-PSSession -Configurationname http://schemas.microsoft.com/powershell/Microsoft.Exchange -ConnectionUri http://localhost/powershell?serializationLevel=Full -Credential $user"
i confronted with the following error

[localhost] Connecting to remote server failed with the following error message : The WinRM client cannot process the r
equest. The WinRM client tried to use Negotiate authentication mechanism, but the destination computer (localhost:80) r
eturned an 'access denied' error. Change the configuration to allow Negotiate authentication mechanism to be used or sp
ecify one of the authentication mechanisms supported by the server. To use Kerberos, specify the local computer name as
the remote destination. Also verify that the client computer and the destination computer are joined to a domain. To u
se Basic, specify the local computer name as the remote destination, specify Basic authentication and provide user name
and password. Possible authentication mechanisms reported by server: For more information, see the about_Remote_Troubl
eshooting Help topic.
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportExc
eption
+ FullyQualifiedErrorId : PSSessionOpenFailed

any help regarding this issue would be appreciated

thanks in advance

Rajith Jose Enchiparambil said...

Hi Cute,

Does the account details stored in variable $user have admin rights on the target server?

Anonymous said...

Hi Rajith

Thanks for your reply .yes $user have admin rights.
Rajith my problem has been resolved by changing this "localhost" to my FQDN in New-PSSession command.

-------------
Best regards,
Cute Devil

Rajith Jose Enchiparambil said...

Glad that the problem is solved. Thanks Cute.

Anonymous said...

I am getting same error. Will you please help me out.

Thanks
Mahesh Bagul

Rajith Jose Enchiparambil said...

Please post the error Mahesh and the command you are trying.

tuandmk47 said...

Hi,
I execute C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command “. ‘C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1′; Connect-ExchangeServer -auto” command from javaprogram but fail ‘emoteExchange.ps1” is not recognized as an internal or external command.
Can you help me?

Source java

String[] command = new String[4];

command[0] = “cmd”;

command[1] = “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command \”. ‘C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1′; Connect-ExchangeServer -auto\”";

command[2] = “$Temp = ConvertTo-SecureString 123456 -asPlainText –Force”;
command[3] = “New-Mailbox -Name tuandm -UserPrincipalName tuandm@metfone.com.kh -OrganizationalUnit metfone.com.kh/metfone/Users -Database metfone -Password $Temp | Set-Mailbox -IssueWarningQuota 136314889 -ProhibitSendReceiveQuota 157286400 -UseDatabaseQuotaDefaults $false”;
Process p = Runtime.getRuntime().exec(command );
p.getOutputStream().close();

Post a Comment