Build a GUI Active Directory Tool using PowerShell Forms πŸ’»

Basic GUI-based Active Directory admin tool

What this tool can do:

  • Create a new AD user
  • Reset a user’s password
  • Disable a user
  • Show output/logs in the GUI

Ad GUI Tool (power Shell)

# Active Directory GUI Tool (PowerShell)

# Requires: RSAT ActiveDirectory module

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

Import-Module ActiveDirectory

# Create Form
$form = New-Object System.Windows.Forms.Form
$form.Text = "Active Directory Admin Tool"
$form.Size = New-Object System.Drawing.Size(500,400)
$form.StartPosition = "CenterScreen"

# Username Label
$lblUser = New-Object System.Windows.Forms.Label
$lblUser.Text = "Username"
$lblUser.Location = New-Object System.Drawing.Point(20,20)
$form.Controls.Add($lblUser)

# Username TextBox
$txtUser = New-Object System.Windows.Forms.TextBox
$txtUser.Location = New-Object System.Drawing.Point(150,20)
$form.Controls.Add($txtUser)

# Password Label
$lblPass = New-Object System.Windows.Forms.Label
$lblPass.Text = "Password"
$lblPass.Location = New-Object System.Drawing.Point(20,60)
$form.Controls.Add($lblPass)

# Password TextBox
$txtPass = New-Object System.Windows.Forms.TextBox
$txtPass.Location = New-Object System.Drawing.Point(150,60)
$txtPass.UseSystemPasswordChar = $true
$form.Controls.Add($txtPass)

# Create User Button
$btnCreate = New-Object System.Windows.Forms.Button
$btnCreate.Text = "Create User"
$btnCreate.Location = New-Object System.Drawing.Point(20,120)
$form.Controls.Add($btnCreate)

# Reset Password Button
$btnReset = New-Object System.Windows.Forms.Button
$btnReset.Text = "Reset Password"
$btnReset.Location = New-Object System.Drawing.Point(150,120)
$form.Controls.Add($btnReset)

# Disable User Button
$btnDisable = New-Object System.Windows.Forms.Button
$btnDisable.Text = "Disable User"
$btnDisable.Location = New-Object System.Drawing.Point(300,120)
$form.Controls.Add($btnDisable)

# Output Box
$outputBox = New-Object System.Windows.Forms.TextBox
$outputBox.Multiline = $true
$outputBox.ScrollBars = "Vertical"
$outputBox.Location = New-Object System.Drawing.Point(20,180)
$outputBox.Size = New-Object System.Drawing.Size(440,150)
$form.Controls.Add($outputBox)

# Button Events

$btnCreate.Add_Click({
    try {
        $user = $txtUser.Text
        $pass = ConvertTo-SecureString $txtPass.Text -AsPlainText -Force
        New-ADUser -SamAccountName $user -Name $user -AccountPassword $pass -Enabled $true
        $outputBox.AppendText("User created: $user`r`n")
    }
    catch {
        $outputBox.AppendText("Error: $_`r`n")
    }
})

$btnReset.Add_Click({
    try {
        $user = $txtUser.Text
        $pass = ConvertTo-SecureString $txtPass.Text -AsPlainText -Force
        Set-ADAccountPassword -Identity $user -Reset -NewPassword $pass
        $outputBox.AppendText("Password reset for: $user`r`n")
    }
    catch {
        $outputBox.AppendText("Error: $_`r`n")
    }
})

$btnDisable.Add_Click({
    try {
        $user = $txtUser.Text
        Disable-ADAccount -Identity $user
        $outputBox.AppendText("User disabled: $user`r`n")
    }
    catch {
        $outputBox.AppendText("Error: $_`r`n")
    }
})

# Run Form
$form.Add_Shown({$form.Activate()})
[void]$form.ShowDialog()

How to use it:

  1. Save it as: ADTool.ps1
  2. Run PowerShell as Administrator
  3. Execute: 
    Set-ExecutionPolicy Bypass -Scope Process

      .\ADTool.ps1



GUI-based Tool to validates environment before running AD Automation scripts

What this tool can do:

  • Runs only validation checks (no AD actions)
  • Clean GUI with:
    • Run Pre-Check button
    • Output panel with results
  • Automatically runs checks on startup
  • Shows clear:
    • Ready
    • Issues
    • Warnings 
Ad GUI Tool (power Shell)

# Active Directory Pre-Check GUI Tool (PowerShell)

# Focus: Only environment validation before running any AD scripts

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

# Try import AD module
try { Import-Module ActiveDirectory -ErrorAction Stop } catch {}

# Create Form
$form = New-Object System.Windows.Forms.Form
$form.Text = "AD Pre-Flight Check Tool"
$form.Size = New-Object System.Drawing.Size(520,420)
$form.StartPosition = "CenterScreen"

# ===== Pre-Check Function =====
function Run-PreCheck {
    $results = @()

    # Admin check
    if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
        $results += "Not running as Administrator"
    } else { $results += "Admin rights OK" }

    # AD module
    if (Get-Module -ListAvailable -Name ActiveDirectory) {
        $results += "AD Module installed"
    } else { $results += "AD Module missing (Install RSAT)" }

    # Domain connectivity
    try {
        if (Test-ComputerSecureChannel) { $results += "Domain connected" }
        else { $results += "Machine not domain joined" }
    } catch { $results += "Domain check failed" }

    # Domain Controller
    try {
        $dc = Get-ADDomainController -Discover -ErrorAction Stop
        $results += "Domain Controller reachable: $($dc.HostName)"
    } catch { $results += "No Domain Controller reachable" }

    # Permissions
    try {
        Get-ADUser -Filter * -ResultSetSize 1 | Out-Null
        $results += "AD read permission OK"
    } catch { $results += "Insufficient AD permissions" }

    # Execution policy
    $policy = Get-ExecutionPolicy
    if ($policy -eq "Restricted") {
        $results += "Execution Policy is Restricted"
    } else {
        $results += "Execution Policy: $policy"
    }

    # Time sync
    try {
        w32tm /query /status | Out-Null
        $results += "Time sync service OK"
    } catch { $results += "Time sync issue" }

    return $results
}

# ===== UI Elements =====

# Title label
$title = New-Object System.Windows.Forms.Label
$title.Text = "Active Directory Environment Validation"
$title.Font = New-Object System.Drawing.Font("Arial",12,[System.Drawing.FontStyle]::Bold)
$title.AutoSize = $true
$title.Location = New-Object System.Drawing.Point(20,20)
$form.Controls.Add($title)

# Run button
$btnRun = New-Object System.Windows.Forms.Button
$btnRun.Text = "Run Pre-Check"
$btnRun.Location = New-Object System.Drawing.Point(20,60)
$btnRun.Size = New-Object System.Drawing.Size(150,30)
$form.Controls.Add($btnRun)

# Output box
$outputBox = New-Object System.Windows.Forms.TextBox
$outputBox.Multiline = $true
$outputBox.ScrollBars = "Vertical"
$outputBox.Location = New-Object System.Drawing.Point(20,110)
$outputBox.Size = New-Object System.Drawing.Size(460,240)
$form.Controls.Add($outputBox)

# ===== Button Event =====
$btnRun.Add_Click({
    $outputBox.Clear()
    $results = Run-PreCheck
    $fail = $false

    foreach ($r in $results) {
        $outputBox.AppendText($r + "`r`n")
        if ($r -like "✘*") { $fail = $true }
    }

    if ($fail) {
        $outputBox.AppendText("`r`n Environment NOT ready\n")
    } else {
        $outputBox.AppendText("`r`n ✘ Environment ready for AD automation\n")
    }
})

# Auto-run on load
$form.Add_Shown({
    $btnRun.PerformClick()
})

[void]$form.ShowDialog()

How to use it:

- Save the Script
  • Open Notepad
  • Paste the GUI script (the one in your canvas)
  • Save as: AD_PreCheck_GUI.ps1

Make sure:

    • File type = All Files
    • Extension = .ps1 (not .txt)
- Open PowerShell (Admin)
  • Click Start
  • Search: PowerShell
  • Right-click → Run as Administrator

- Allow Script Execution (Temporary) 
    Run Script:
    Set-ExecutionPolicy Bypass -Scope Process

Note: This only works for current session (safe)

- Navigate to Script Location
    Example: cd C:\Scripts

- Run the GUI Tool
    Script: .\AD_PreCheck_GUI.ps1

- How the GUI Works
    When it opens:
    Auto-run: Pre-check runs automatically on startup
    Run Pre-Check Button: Click anytime to re-check

- Understand Output
Example (Good Environment)

        Admin rights OK
        AD Module installed
        Domain connected
        Domain Controller reachable
        AD read permission OK
        Execution Policy: RemoteSigned
        Time sync service OK

        
  Environment ready for AD automation

Example (Issues Found)

        Not running as Administrator
        AD Module missing
        Machine not domain joined

        
✘  Environment NOT ready

====== Few Important Reason for Errors ======

Not admin          Run PowerShell as Administrator
AD module missing  Install RSAT
Not domain joined  Join system to domain
No DC reachable    Check network / VPN
No permission      Contact AD admin

How to  Make it one-click tool

Option 1: Right-click file → Create Shortcut

Option 2(Best): Create a .bat file

Bat File script: 
powershell -ExecutionPolicy Bypass -File "C:\Scripts\AD_PreCheck_GUI.ps1"



Subscribe to my YouTube channel: www.youtube.com/@Stack_Tech



Comments

Popular posts from this blog

Active Directory Overview (Windows Server) for Interview Preparation

Desktop Support Interview Q&A (Beginner Level)

IT Abbreviations Explained for Beginners | Most Asked in Interviews