ASP.NET - AD Unlock-Account [Answered]RSS

1 reply

Last post Jan 20, 2020 07:01 AM by Jalpa Panchal

  • ASP.NET - AD Unlock-Account

    Jan 18, 2020 05:11 PM|tomiPol|LINK

    Hi, I'm new user in this forum and beginner programer so asking for your understanding.

    I would like to create mini web application for Active Directory controller. I tried to modify the template that I found on the internet. I don't know how to change the code correctly, I want to be able to check if the user is blocked and have a separate button to unlock.

    Thanks all the help.!

    WebForm1.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Management.Automation;
    using System.Management.Automation.Runspaces;
    using System.Text;
    
    namespace ITDropletsPowershell
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
            }
            protected void UNLOCKUSERClick(object sender, EventArgs e)
            {
                Result.Text = string.Empty;
    
                InitialSessionState iss = InitialSessionState.CreateDefault2();
    
                var shell = PowerShell.Create(iss);
    
                /*shell.Commands.AddCommand("Get-ChildItem");*/
                /*shell.Commands.AddCommand("hostname");*/
                shell.Commands.AddParameter("Path", Input.Text);
    
                try
                {
                    var results = shell.Invoke();
    
                    if (results.Count > 0)
                    {
    
                        var builder = new StringBuilder();
    
                        foreach (var psObject in results)
                        {
                            builder.Append(psObject.BaseObject.ToString() + "\r\n");
                        }
    
                        Result.Text = Server.HtmlEncode(builder.ToString());
                    }
                }
                catch (ActionPreferenceStopException Error) { Result.Text = Error.Message; }
                catch (RuntimeException Error) { Result.Text = Error.Message; };
            }
        }
    }

    WebForm1.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ITDropletsPowershell.WebForm1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>USER MANAGER</title>
    </head>
    <body>
        <form id="form2" runat="server">
            <div>
                <div><h1 align="center">UNLOCK USER ACCOUNT</h1></div>
                <p>PLEASE GIVE USER SKP (ex. FORMAT 123987):
                    <asp:TextBox ID="Input" runat="server" Width="30%" Height="20px" ></asp:TextBox>
                </p>
                <asp:Button ID="UNLOCKUSER" runat="server" Text="UNLOCK USER" Width="150" onclick="UNLOCKUSERClick" />
                <asp:Button ID="Button1" runat="server" Text="CHECK USER" Width="150" />
                <p>Result
                <asp:TextBox ID="Result" TextMode="MultiLine" Width="100%" Height="450px" runat="server"></asp:TextBox>
                </p>
    
            </div>
        </form>
    </body>
    </html>

  • Re: ASP.NET - AD Unlock-Account

    Jan 20, 2020 07:01 AM|Jalpa Panchal|LINK

    Hi,

    Your issue is not related to iis. This forum discusses issues about IIS and PowerShell integration. Use this forum to ask PowerShell questions, discuss issues, request features and yell at IIS team members.

    I suggest you post the issue in asp.net forum.

    https://forums.asp.net/

    and your codes don't relate to AD. I suggest you post your question in asp.net forum with more detail like what is your issue, what error did you face, what is your exact requirement.

    Thanks for understating.

    Regards,

    Jalpa

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.