0

I have two functions readFromFile(path) and writeToFile(path). And I have the credentials to connect to the remote machine. My goal is to be able to run those two functions on the remote machine. In PowerShell, I used Invoke-Command to run those set of commands in the remote machine. Is there an alternative to it in c#? If so please help me on using it

  • Just _any_ "remote" machine? – Fildor May 03 '21 at 09:45
  • Any machine in the domain – Pendela sai komal May 03 '21 at 09:55
  • Look into WCF service reference – user3248578 May 03 '21 at 10:17
  • My use case requires not to make any change in the remote machine other than to that single file. – Pendela sai komal May 03 '21 at 10:33
  • Then use an UNC path (i.e. Network share). – Fildor May 03 '21 at 10:49
  • The file might not be a shared file. I used `Invoke-Command` previously and it worked fine. Now am trying to port it to c#. – Pendela sai komal May 03 '21 at 11:14
  • Does this answer your question? [How to execute a command in a remote computer?](https://stackoverflow.com/questions/428276/how-to-execute-a-command-in-a-remote-computer) – Charlieface May 03 '21 at 12:23
  • Nope in that, it is mentioned as a shared folder and also the function I want to execute is not in the remote machine. My requirement is similar to `Invoke-Command` i just connect to the remote machine scope and execute my function there. – Pendela sai komal May 03 '21 at 13:34
  • @Pendelasaikomal You realize that `Invoke-Command` _does_ execute code on the remote machine? The difference is that PowerShell is installed in the remote machine. So your local PowerShell can tell your remote PowerShell to invoke one of its commandlets. You don't have that with C# code. You either need access to the remote filesystem to read/write to it, or you need a remote service to send / receive data and do File I/O for you. – Fildor May 03 '21 at 15:00
  • Is there a way to access the remote file system in the domain using c#? – Pendela sai komal May 04 '21 at 11:08

0 Answers0