title: How to create a local windows user account using remote powershell?
body: <p>tried creating users with powershel.This worked fine for local machine. But how to create a local user account in a remote machine using remote powershell?</p>
  
  <p>The script localwindows.ps1 is </p>
  
  <pre><code>$comp = [adsi]'WinNT://machinename,computer';
  $user = $comp.Create('User', 'account4');
  $user.SetPassword('change,password.10');
  $user.SetInfo();
  </code></pre>
  
  <p>I tried the same thing through C# : </p>
  
  <pre><code>            PSCredential credential = new PSCredential(userName, securePassword);
              WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, "machinename", 5985, "/wsman", shellUri, credential);
              using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo))
              {
  
                  runspace.Open();
                   String file = "C:\\localwindows.ps1";
                   Pipeline pipeline = runspace.CreatePipeline();
                   pipeline.Commands.AddScript(System.IO.File.ReadAllText(file));                    
                   pipeline.Commands.Add("Out-String");
  
                   // execute the script 
                   Collection&lt;PSObject&gt; results = pipeline.Invoke();
                }  
  </code></pre>
  
  <p>This also works fine  locally .But for remote computer its throwing exception "create :Access is denied ". </p>