Display output of PowerShell script in hta

I am trying to create a GUI for our helpdesk staff to use to unlock users’ accounts. Basically, I want to launch an hta, then the staff will enter the user’s name into an inputbox, which will get saved as a variable. Then I would like for to use PowerShell to take that variable and determine whether or not the account is locked, and if so, to unlock and to display a message back to the hta.

I have the PowerShell code itself working fine. What I am struggling with is utilizing the hta to both get the value and display the results. Is this even possible? Or is there a better way of doing this? Any help is appreciated.

PowerShell code below:

# Prompt for username
$username = Read-Host "Enter the username to unlock"

# Get the user account
$username = Get-ADUser -Identity $username

if ($user) {
    # Check if the account is locked out
    try {
        $User = Get-ADUser -identity $username
        if ($User.LockedOut) {
            Unlock-ADAccount -identity $User
            $msg = "Account " + '$username' + " has been unlocked."

        } else {
            $msg = "Account " + $User + " is not locked out"
    } catch {
        $msg = "Cannot find account with that name"

    Write-Host $msg

Educate / elevate / enlighten your helpdesk staff to be able to use two simple PowerShell cmdlets.

IMO there is no benefit in wrapping basic PowerShell cmdlets in a GUI if there is no other benefit than having a white window and black text. :man_shrugging:t3:

What you actually do with projects like this - you introduce another layer of complexity with additional sources of errors.

1 Like

You posted the code that is working but not the hta code that you’re having trouble with. Olaf’s strong point aside, how are we supposed to help with the HTA if we can’t see it or play with it? I’d also recommend going a bit more simple by using Out-GridView. You can query all users and display them with Out-Gridview, the tech can type all or part of the username in question, select it in the list, hit ok, and the script can do it’s thing. You can use a shortcut or a bat file to make the script “clickable”

1 Like

Just out of curiosity, where is this variable defined? I see that you define it again in your Try/Catch block.

HTAs don’t support PowerShell. You can build GUI applications similar to HTAs using WPF or XAML. But, as Olaf suggested, this is not the pattern for PowerShell. Empower your helpdesk by teaching them to use PowerShell as a tool, not to use a tool that hides the complexity from them.


Thank you all for your advice. I am going to take it and not bother with the hta. I may take a look at WPF or XAML as @swsamwa suggested. But it also looks we have some other work to do first such as verifying group permissions, etc. are concerned. It’s been awhile since the tool they were using before actually worked correctly.