1
Reply

Powershell to web

S Sakrigue

S Sakrigue

Jul 13 2016 10:16 AM
277
Hello guys,
I try to create a Web page for end users to change their own password alone in active directory.
I used Powershell script in C #. When I executed the code, the following error appears [Incomplete ParseException: The Terminator "is missing in the chain.]
 help please!!
Thank you!!
NB :I have to work with Powershell.
  1. using System;  
  2. using System.Management.Automation;  
  3. using System.Text;  
  4.   
  5. namespace PowerShellExecution  
  6. {  
  7.     public partial class Default : System.Web.UI.Page  
  8.     {  
  9.         protected void Page_Load(object sender, EventArgs e)  
  10.         {  
  11.   
  12.         }  
  13.   
  14.         protected void ExecuteCode_Click(object sender, EventArgs e)  
  15.         {  
  16.             // Clean the Result TextBox  
  17.             ResultBox.Text = string.Empty;  
  18.             // Validate the input 
  19.             var usr = user.Text;  
  20.             var op = oldpwd.Text;  
  21.             var np = newpwd.Text;  
  22.             var np1 = newpwd1.Text;  
  23.             // Initialize PowerShell engine  
  24.             
  25.             using (PowerShell shell = PowerShell.Create())  
  26.             {  
  27.                 string pwdScript = "Set-ADAccountPassword -Identity \"" + usr + "\"  -Oldpassword  \"" + op + "\"  -NewPassword \"" + np ;  
  28.                 {  
  29.                     
  30.                     shell.AddScript(pwdScript);  
  31.                     // Execution du script  
  32.                     var results = shell.Invoke();  
  33.                    
  34.                     if (results.Count > 0)  
  35.                     {  
  36.                      
  37.                         var builder = new StringBuilder();  
  38.   
  39.                         foreach (var psObject in results)  
  40.                         {  
  41.                              
  42.                             builder.Append(psObject.BaseObject.ToString() + "\r\n");  
  43.                         }  
  44.   
  45.                        
  46.                         ResultBox.Text = builder.ToString();  
  47.                     }  
  48.                 }  
  49.             }  
  50.         }  
  51.     }  
  52. }  

Answers (1)