Quantcast
Channel: Exchange Server 2013 - Administration, Monitoring, and Performance 论坛
Viewing all articles
Browse latest Browse all 8719

Accessing Exchange server 2013 from window 7 using Remote PowerShell?

$
0
0
I am trying Remote PowerShell from Windows 7 to Exchange Server 2013. Following is the code snippet.
         

            public static void ConnectToPowerShell()
        {
            string password = "password";
            string userName = "Administrator";

            System.Uri uri = new Uri(@"http://ExchangeServer/powershell?serializationLevel=Full");
            System.Security.SecureString securePassword = String2SecureString(password);

            System.Management.Automation.PSCredential creds = new System.Management.Automation.PSCredential(userName, securePassword);

            Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace();

            PowerShell powershell = PowerShell.Create();
            PSCommand command = new PSCommand();
            command.AddCommand("New-PSSession");
            command.AddParameter("ConfigurationName", "Microsoft.Exchange");
            command.AddParameter("ConnectionUri", uri);
            command.AddParameter("Credential", creds);
            command.AddParameter("Authentication", "Default");
            PSSessionOption sessionOption = new PSSessionOption();
            sessionOption.SkipCACheck = true;
            sessionOption.SkipCNCheck = true;
            sessionOption.SkipRevocationCheck = true;
            command.AddParameter("SessionOption", sessionOption);

            powershell.Commands = command;

            try
            {
                // open the remote runspace
                runspace.Open();

                // associate the runspace with powershell
                powershell.Runspace = runspace;

                // invoke the powershell to obtain the results
                Collection<PSSession> result = powershell.Invoke<PSSession>();
                String str=null;
                foreach (ErrorRecord current in powershell.Streams.Error)
                {
                    // Console.WriteLine("The following Error happen when opening the remote Runspace: " + current.Exception.ToString() +
                    // " | InnerException: " + current.Exception.InnerException);
                    str = "The following Error happen when opening the remote Runspace: " + current.Exception.ToString() +
                       " | InnerException: " + current.Exception.InnerException;
                    MessageBox.Show(str);
                }
                if (result.Count != 1)
                    throw new Exception("Unexpected number of Remote Runspace connections returned.");

                // Set the runspace as a local variable on the runspace
                powershell = PowerShell.Create();
................................
...............................
}


At the line: 
       
           Collection<PSSession> result = powershell.Invoke<PSSession>();

This gives exception:
The following Error happen when opening the remote Runspace: System.Management.Automation.Remoting.PSRemotingTransportException: Connecting to remote server failed with the following error message : 
The WinRM client cannot process the request. The WinRM client tried to use Negotiate authentication mechanism, but the destination computer (rmex13:80) returned an 'access denied' error. 
Change the configuration to allow Negotiate authentication mechanism to be used or specify 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 use 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_Troubleshooting Help topic


How can i fix this type of exception? 

Thanks,
Azam!!

Viewing all articles
Browse latest Browse all 8719

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>