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!!
- using System;
- using System.Management.Automation;
- using System.Text;
- namespace PowerShellExecution
- {
- public partial class Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void ExecuteCode_Click(object sender, EventArgs e)
- {
- // Clean the Result TextBox
- ResultBox.Text = string.Empty;
- // Validate the input
- var usr = user.Text;
- var op = oldpwd.Text;
- var np = newpwd.Text;
- var np1 = newpwd1.Text;
- // Initialize PowerShell engine
- using (PowerShell shell = PowerShell.Create())
- {
- string pwdScript = "Set-ADAccountPassword -Identity \"" + usr + "\" -Oldpassword \"" + op + "\" -NewPassword \"" + np ;
- {
- shell.AddScript(pwdScript);
- // Execution du script
- var results = shell.Invoke();
- if (results.Count > 0)
- {
- var builder = new StringBuilder();
- foreach (var psObject in results)
- {
- builder.Append(psObject.BaseObject.ToString() + "\r\n");
- }
- ResultBox.Text = builder.ToString();
- }
- }
- }
- }
- }
- }
Nitin SontakkePosted Jul 13, 2016, 11:57 AM