iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
😊

[PowerShell] Rebuilding my custom tool with AI: How it outperformed my original code

に公開

Introduction: Encountering the "Ultimate Subordinate" — AI

Previously, I introduced an "Inquiry Management System" using PowerShell in the following article:

[https://zenn.dev/sho_sol/articles/dd971b67474465]

[Beyond Excel] 0 budget, no server. The full picture of an "Inquiry Management System" built only with PowerShell

That was useful in its own right and helped out in the field.
However, the other day, it occurred to me: "What would happen if I tried developing this tool through pair programming with Generative AI?"

Let me start with the conclusion.
In just a few hours of "dialogue," a tool was completed that is far more robust, feature-rich, and user-friendly than the code I had spent several days writing.

My pride as an engineer was slightly wounded (laughs), but more than that, I felt the critical importance of the "skill to direct AI."
In this article, I will share the full picture of the "Complete Edition Inquiry Management System" built together with AI, as well as the "pitfalls and workarounds of AI coding" that I encountered during development.

1. What Changed After Rebuilding with AI (Before / After)

My previous self-made system also featured "AD integration" and "pseudo-concurrency control," but after upgrading it through repeated dialogues with AI, the following features were added:

① Visual Alert Function (UI Evolution)

To address the on-site challenge of "it's hard to tell which cases are approaching their deadlines," I implemented a function that automatically changes the background color of list rows.

  • 🔴 Red: Overdue (urgent cases are obvious at a glance)
  • 🟡 Yellow: Within 3 days of deadline (configurable)
  • ⚪ White: Normal
  • 🔘 Gray: Completed

Implementing this with WPF (Windows Presentation Foundation) XAML descriptions is a pain, but with AI, it was done in an instant.

② Independent Settings Screen and Persistence

Features that were previously hard-coded, such as the "number of days for warnings" and "number of items to save," can now be changed via a GUI settings screen.
Settings are saved to an XML file and are maintained even when the application is restarted.

③ Automatic File Repair Function (Improved Robustness)

This is the biggest difference.
If the CSV file becomes corrupted for some reason (e.g., forced termination) or the header row gets messed up, I implemented a function that automatically detects it at startup, takes a backup, and resets the file to a healthy state.
This is a crucial feature for creating a "tool that doesn't fail in the field."


2. The "Key Hurdles" of AI Coding and the Value of Engineer Intervention

"Does this mean you can just leave everything to AI with zero knowledge?" It turned out that wasn't the case.
While AI is excellent, it doesn't know the "real-world circumstances" or "environment-specific behaviors."
This is where an engineer's knowledge (requirement definition and troubleshooting skills) becomes indispensable.

I'll share the points where I actually got stuck and how I solved them by giving instructions.

Hurdle 1: The Date Entry Issue (WPF Specifications)

When retrieving a date from a DatePicker control, the AI initially suggested a syntax like .Value.ToString().
However, depending on the environment, this could be treated as Null, resulting in a bug where the date that was supposed to be registered would disappear.

In response, I instructed the AI to change it to the "most robust method that doesn't depend on the environment."

# × AI's suggestion (Doesn't work in some environments)
# $sDate = $dtpDue.SelectedDate.Value.ToString("yyyy/MM/dd")

# ○ After fix (Force type conversion using PowerShell's casting feature)
$sDate = ""
if ($dtpDue.SelectedDate) {
    $sDate = "{0:yyyy/MM/dd}" -f [DateTime]$dtpDue.SelectedDate
}

This fix of just a few lines determined the overall reliability of the tool.

Hurdle 2: Data Loss Bug (The Trap of Object Manipulation)

When saving a CSV in PowerShell, it's common to format the columns using Select-Object before running Export-Csv.
However, with the object structure in this project, a phenomenon occurred where column contents became empty under specific conditions, leading to data loss.

To address this, I gave the following instruction: "Stop using high-level processing like object conversion. Change it to a primitive logic that creates the CSV row directly as a string and appends it."

# After fix: Physically create a string and append (Ensures data is never lost)
function Append-CsvLine($filePath, $values) {
    $line = ""
    foreach ($val in $values) {
        # Escape double quotes
        $safeVal = $val -replace '"', '""'
        $line += "`"$safeVal`","
    }
    $line = $line.TrimEnd(",")
    
    # Specify character encoding as Default (Shift-JIS)
    $line | Out-File $filePath -Append -Encoding default
}

It's an old-school approach, but for business tools, "code that definitely works" is more valuable than "smart code."


3. Summary: Future Development Style

What I felt through this development is that "my coding skills were not in vain."
While AI produces "80-point" working code, the expertise of an engineer who understands "why it doesn't work" and "how it should behave in the field" was indispensable to elevate it to a "100-point (or 120-point)" tool usable in a real-world environment.

  • AI: The "Implementation Lead" writing code at overwhelming speeds.
  • Human: The "PM and Architect" defining requirements, ensuring quality, and guiding the AI.

By establishing this division of labor, even a single person can build enterprise-level business systems at incredible speed.
For those in workplaces that have given up on systematization due to a lack of budget, I encourage you to try building tools for yourselves using PowerShell and AI.

4. [Distribution] About the Complete Source Code

The full source code (v46.0) of the tool created this time, along with setup procedures that can be used immediately via copy-and-paste and detailed development logs, has been compiled in this Zenn Book.

[ https://zenn.dev/sho_sol/books/d1913893205d91 ]

  • InquiryManager.ps1 (The main system)
  • InquiryManager.vbs (A startup script to prevent the black console window from appearing)

If you find writing code to be a hassle but want to use the tool right away, or if you want to learn more about the development process using AI, please check out the Book.

Discussion