1

I have a c# app that uses winrm to connect to other machines. In order to make it work, I need to run the powershell command:

Set-Item WSMan:\localhost\Client\TrustedHosts -Value $ip -Force

or winrm command:

winrm set winrm/config/client '@{TrustedHosts="10.0.5.35"}'

I was wondering what is the equivalent of that in c#?

max
  • 9,708
  • 15
  • 89
  • 144
  • http://msdn.microsoft.com/en-us/library/dd163506.aspx so how come you can't create a console app or run it from a CMD line and utilize along with it the `Process` Class and CMD line args[] to run the same params – MethodMan Dec 01 '14 at 21:04
  • possible duplicate of [Connecting to remote server failed using WinRM from PowerShell](http://stackoverflow.com/questions/16010091/connecting-to-remote-server-failed-using-winrm-from-powershell) – MethodMan Dec 01 '14 at 21:05
  • here are some more links / suggestions you can read http://stackoverflow.com/questions/16323948/running-remote-powershell-commandlet-that-wraps-a-process-exits-before-completio – MethodMan Dec 01 '14 at 21:06
  • thanks but the emphasis is on using C#. Calling powershell from c# is bad practice / last way out. There must be an api in System.Management namespace but I have not found it yet. – max Dec 01 '14 at 21:16
  • why do you think it's bad practice ..? I am just curious.. sounds like you could create a `Batch File` and invoke the process that way if worse comes to worse.. – MethodMan Dec 01 '14 at 21:17
  • There are several reasons. In my app, this is not a one-time setup. It's going to be done many times per day for many hosts. First, switching languages: it makes the code high maintenance. Imagine what happens if on windows 2008 I need to install a powershell plugin to make this work...Second comes performance. It's likely that I'll run 10 threads with intensive large stdout. Each will result in a separate process which is not sharing memory hence the overhead. In short, I'll use powershell as a last resort. – max Dec 01 '14 at 23:56

0 Answers0