Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PowerShell AD Query Translator

A Streamlit application that converts plain-English Active Directory (AD) requests into PowerShell Get-AD* commands using the OpenAI API, with validation, logging, and a local fallback mode.

Features

  • Translate natural language into PowerShell AD query commands
  • Restrict generated output to read-only Get-AD* style commands
  • Block potentially unsafe modification command patterns (Remove-, Set-, Add-)
  • Streamlit UI with:
    • built-in example prompts
    • syntax-highlighted PowerShell output
    • query history and favorites
  • Environment-driven configuration via .env
  • Logging for app activity and translation errors

Project Structure

.
├── main.py          # Streamlit UI
├── translator.py    # Prompting, model call, and command validation
├── config.py        # Environment/config loading
├── requirements.txt # Python dependencies
└── README.md

Requirements

  • Python 3.9+
  • Access to OpenAI API (unless using local fallback mode)

Install dependencies:

pip install -r requirements.txt

Configuration

Create a .env file in the project root:

OPENAI_API_KEY=your_openai_api_key_here
USE_LOCAL_MODEL=False

Environment Variables

  • OPENAI_API_KEY: Required when USE_LOCAL_MODEL=False
  • USE_LOCAL_MODEL: True or False (default: False)

Note: Local fallback is currently a stub and does not perform real translation.

Run the Application

streamlit run main.py

Then open the local URL shown by Streamlit (typically http://localhost:8501).

Example Queries

  • Find users who haven't logged in for 90 days
  • Show all admin groups
  • List service accounts
  • Check if a user is a member of a group
  • Find computers in the HR department
  • Identify disabled accounts

How Translation Works

  1. The app builds a prompt from your natural language query.
  2. The OpenAI Completion API generates a PowerShell command.
  3. The output is validated to ensure it is AD query-oriented and non-destructive.
  4. The resulting command is displayed with syntax highlighting.

Logs

  • app.log: Streamlit application events
  • query.log: Translation requests and errors

License

This project is licensed under the MIT License.

About

Plain english active directory requests into powershell commands

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages