Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Connecting to remote powershell using C# development

$
0
0

Hi guys,

I'm trying to use C# to connect to a powershell on a remote server,

here is the code:

string liveIDConnectionUri = "https://vm-milad/powershell";string schemaUri = "http://schemas.microsoft.com/powershell/Microsoft.Exchange";

            SecureString SecPass = new SecureString();string password = "Qwert..";foreach (char c in password)
            {
                SecPass.AppendChar(c);
            }

            PSCredential ali = new PSCredential("mcmilad\administrator", SecPass);//WSManConnectionInfo connectionInfo = new WSManConnectionInfo();
            WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri(liveIDConnectionUri),schemaUri,ali);

            connectionInfo.SkipCNCheck = true;
            connectionInfo.SkipRevocationCheck = true;
            connectionInfo.SkipCACheck = true;
            connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;            using (RunspacePool runspace = RunspaceFactory.CreateRunspacePool(1, 2, connectionInfo))
            {

                runspace.Open();
            }

and here is the WinRM setting on the remote server:

Allow unencrypted traffic : true

Basic authentication : true

By the way, I have already ran winrm /quickconfig and I have configured listeners for winrm as well.

but it ends un with "Access denied" error, any ideas?


Viewing all articles
Browse latest Browse all 21975

Trending Articles



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