Я попытался следующий код, чтобы получить почтовый ящик от обмена server.I я встречая проблема при запуске программыОшибка при выполнении команды Exchange PowerShell из C# программы
static void Main(string[] args)
{
string user = "Domain\\username";
SecureString passwd = new SecureString();
foreach (char c in "Password")
{
passwd.AppendChar(c);
}
PSCredential cred = new PSCredential(user, passwd);
WSManConnectionInfo ConnInfo = new WSManConnectionInfo(new Uri(liveIdconnectionUri), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", cred);
ConnInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
ConnInfo.MaximumConnectionRedirectionCount = 2;
//ConnInfo.ProxyAccessType = System.Management.Automation.Remoting.ProxyAccessType.AutoDetect;
Runspace ExchangeRunspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(ConnInfo);
PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();
command.AddCommand("Get-Mailbox");
command.AddParameter("Identity", user);
powershell.Commands = command;
// open the remote runspace
ExchangeRunspace.Open();
// associate the runspace with powershell
powershell.Runspace = ExchangeRunspace;
// invoke the powershell to obtain the results
powershell.Invoke();
Collection<PSObject> results = powershell.Invoke();
foreach (PSObject obj in results)
{
PSMemberInfoCollection<PSPropertyInfo> propInfos = obj.Properties;
Console.WriteLine("********************");
foreach (PSPropertyInfo propInfo in propInfos)
{
string propInfoValue = (propInfo.Value == null) ? "" : propInfo.Value.ToString();
Console.WriteLine("{0} --> {1}", propInfo.Name, propInfoValue);
}
}
Console.ReadLine();
}
Я получаю следующее сообщение об ошибке во время работы выше код
Connecting to remote server failed with the following error message : WinRM cannot process the request. The following error occured while using Kerberos authentication: There are currently no logon servers available to service the logon request.
Possible causes are:
-The user name or password specified are invalid.
-Kerberos is used when no authentication method and no user name are specified.
-Kerberos accepts domain user names, but not local user names.
-The Service Principal Name (SPN) for the remote computer name and port does not exist.
-The client and remote computers are in different domains and there is no trust between the two domains.
After checking for the above issues, try the following:
-Check the Event Viewer for events related to authentication.
-Change the authentication method; add the destination computer to the WinRM TrustedHosts configuration setting or use HTTPS transport.
Note that computers in the TrustedHosts list might not be authenticated.
-For more information about WinRM configuration, run the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic."
Даже когда я запускаю команду 'New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionURI $ liveIdconnectionUri -credential "[email protected]" -Authentication керберос', я получаю ту же ошибку.
Любой указатель для решения этого вопроса будет действительно полезен. Спасибо заранее.
Я использовал «New-MoveRequest» так же, как вы можете использовать любую команду здесь. - спасибо -Hitesh shrimali –