title: How I can remove a ADUser with System.Management.Automation in C#?
body: <p>I use System.Management.Automation for work with the powershell and c# and I want to use the Remove-ADUser command but I get a error: Here my Code. </p>
  
  <pre><code>public bool RemoveADUser(string sAMAccountName) { 
  
              Security key = new Security();
  
              try
              {
                  ADPASSWORD = key.PasswordDecrypt("vnPYuGoPSvrSjDC+/5lUTQ==");
                  //ADPASSWORD = "vnPYuGoPSvrSjDC+/5lUTQ==";
  
                  SecureString SECUREADADMINPASSWORD = new SecureString();
  
                  foreach (char x in sAMAccountName)
                  {
                      SECUREADADMINPASSWORD.AppendChar(x);
                  }
  
                  SecureString pw = new SecureString();
  
                  foreach (char x in ADPASSWORD)
                  {
                      pw.AppendChar(x);
                  }
  
                  InitialSessionState initial = InitialSessionState.CreateDefault();
                  Environment.SetEnvironmentVariable("ADPS_LoadDefaultDrive", "0");
                  initial.ImportPSModule(new string[] { "ActiveDirectory" });
  
                  PSCredential crend = new PSCredential(ADNAME, pw);
  
                  using (Runspace runspace = RunspaceFactory.CreateRunspace(initial))
                  {
                      runspace.Open();
                      using (Pipeline p = runspace.CreatePipeline())
                      {
                          Command command = new Command("Remove-ADUser");
                          command.Parameters.Add("Identity", sAMAccountName);
                          command.Parameters.Add("Credential", crend);
  
                          p.Commands.Add(command);
  
                          p.Invoke();
  
                          return true;
  
                      }
                  }
              }
              catch (Exception)
              {
  
                  return false;
              }
              finally
              {
  
              }
          }
  </code></pre>
  
  <p>the Code go to  p.Invoke(); but then I get this message:</p>
  
  <p>in german:</p>
  
  <p>Fehler in einem Befehl mit einer Eingabeaufforderung. Vom Hostprogramm oder Befehlstyp wird keine Benutzerinteraktion unterstützt. Für den Versuch, die Bestätigung anzufordern, wurde vom Host folgende Meldung verwendet: Möchten Sie diese Aktion wirklich ausführen?</p>
  
  <p>in english:</p>
  
  <p>Error in a command with a command prompt.The host program or command type isn't supported user interaction. For the experiment, to request confirmation, the following message from the host used was: Do you want to perform this action?</p>