I need to run PowerShell script on our exchange server. I've enabled PS-Remoting and WinRM-quickconfig on both my local machine and SMTP server. When i try to connect I receive the error below.
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.
Here is my connection code below NOTE: I can connect to SMTP server with this user account using RDP
public static void Main(string[] args)
{
//CREATE SECURE STRING PASSWORD
string pwd = "MyPasswordAsAString";
char[] cpwd = pwd.ToCharArray();
SecureString pass = new SecureString();
foreach (char c in cpwd)
pass.AppendChar(c);
//CREATE PS CREDENTIAL
PSCredential Credential = new PSCredential("Domain\\Username", pass);
//RESOURCE URI
string shell = "http://schemas.microsoft.com/powershell/Microsoft.PowerShell";
//ADDRESS OF SMTP SERVER
var target = new Uri("HTTP://FULLYQUALIFIEDDOMAINNAME");
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(target, shell, Credential );
//CREATE RUNSPACE
Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
//OPEN CONNECTION
runspace.Open();
using (PowerShell ps = PowerShell.Create())
{
ps.Runspace = runspace;
ps.AddScript("Get-Service");
var results = ps.Invoke();
// Do something with result ...
}
runspace.Close();
//AFTER FILE IS CREATED THROUGH POWERSHELL READ IT WITH EXCELL
DataTable PF2 = processFile(@"C:\inetpub\Clients\MLK\confRooms-permissions.xlsx", "xlsx");
importData(PF2);
}