Which local AI model writes code that works: 132 PowerShell scripts

Ten local AI model variants, 12 logic problems and 132 PowerShell scripts actually run: which ones write code that works and how the others fail.

A terminal window with a prompt inside a hexagon, a box with 0 of 12 marked with a red X and the label 210 TOK/S, one with 11 of 12 checked in green and the label 18 TOK/S, the label 132 SCRIPTS and the title It writes code, but does it run?

In short

Math and logic tests do not tell local models apart: seven of ten variants answered correctly in at least 33 of 36 runs. PowerShell scripts, actually run, do: only gpt-oss:20b and Qwen3-30B-A3B Instruct wrote 11 correct scripts out of 12. Of 132 scripts, 53 worked, and 22 ran without an error and gave a wrong result. Thinking helps small models but can leave them out of budget, and 3-bit quantization hurts code most of all.

In the article on hardware we measured how fast each local model writes on five computers. The fastest 5 GB model generated 210 tokens per second on our test PC. That left the question that matters to anyone who actually wants to use the model: does it write something you can rely on?

We gave the same tasks to ten model variants, on the same PC. First the 12 math, logic and code problems from the article on thinking mode. Then four small admin tasks, for each of which the model had to write a PowerShell script. We did not read the scripts to grade them. We ran them.

The problem test does not tell the models apart; the test where the code has to run tells them apart at once. On the problems, seven variants out of ten got at least 33 correct answers out of 36. On the scripts, only two get past 7 out of 12, and the fastest model did not write a single script that works.

What we tested

All runs were done through Ollama 0.40.17, on the PC with the RTX 3060 Ti from the previous articles, with a context window of 8,192 tokens and each model's default settings. The answer was capped at 2,048 tokens without thinking and at 7,168 with thinking.

All prompts were written in Romanian, because we test the models for Romanian companies. This matters for two of the models, as we explain further down.

Model in Ollama Size on disk Mode tested
qwen3:4b and qwen3:4b-instruct 2.5 GB with and without thinking, respectively
qwen3:8b 5.2 GB with and without thinking
lfm2.5:8b-a1b 5.2 GB always thinks
granite3.1-moe:3b 2.0 GB no thinking
gpt-oss:20b 14 GB always thinks
qwen3:30b and qwen3:30b-instruct 19 GB with and without thinking, respectively
Qwen3-30B-A3B Instruct, 3-bit 14.7 GB no thinking

Two notes on the modes. In the Ollama library, qwen3:4b and qwen3:30b are the Thinking-2507 variants, which always think, and their non-thinking counterparts carry the -instruct suffix. Only qwen3:8b is the hybrid model, where thinking can be switched on and off.

lfm2.5:8b-a1b thinks even when you ask it not to: with think: false, the reasoning shows up directly in the answer. So we report its thinking runs, where the answer comes out clean.

The 12 problems: almost every model gets a high score

Each problem has a single answer that can be checked automatically, and each was run three times. The results for qwen3:8b, qwen3:30b and qwen3:30b-instruct are the ones published in October. The rest are new.

Model Mode Correct out of 36 Tokens, median
gpt-oss:20b thinking 36 230
qwen3:4b thinking 36 1,097
qwen3:8b thinking 36 752
qwen3:30b thinking 36 1,055
Qwen3-30B-A3B Instruct, 3-bit none 36 193
qwen3:4b-instruct none 34 324
qwen3:30b-instruct none 33 203
qwen3:8b none 30 225
lfm2.5:8b-a1b thinking 28 477
granite3.1-moe:3b none 4 135

Five variants got the maximum score, including a 2.5 GB model. gpt-oss:20b reached the same score with three to five times fewer tokens than the Qwen3 models with thinking.

We were lenient with lfm2.5:8b-a1b on form: we accepted “Final answer” instead of the Romanian “Răspuns final”, and English words such as “cavalier” or “truth-teller” instead of the Romanian “cavaler” (knight). The mistakes that remain are of substance. For the last digit of 7 to the power of 2026 it answered 7 in all three runs, although the correct answer is 9. Asked “which is larger, 9.11 or 9.9?”, it picked 9.11 twice out of three times.

granite3.1-moe:3b could not be graded fairly on these problems. Its answers are in broken Romanian, along the lines of “rezervorul se va umpla cu un cont 10 l/min” (roughly: “the tank will fill with an account 10 l/min”).

From problems to scripts

A math problem has a single answer, which the model can check in its head. A script has to be right in every character and use only commands that exist. We chose four tasks an administrator might ask for on an ordinary day:

  1. extensions: count the files in a folder and add up their size by extension, sorted by size.
  2. log: count the lines with the ERROR level in a log file, per day.
  3. inactive: pull out of a CSV the users who have not logged in for more than 90 days.
  4. cidr: write a function that says whether an IP address belongs to a network in CIDR notation, and apply it to six pairs.

Each task has fixed input data and an exact output. We explicitly asked for Windows PowerShell 5.1, the one installed on every Windows machine, and ran every generated script. Its output was compared line by line with the expected one. Each model got each task three times, so 12 scripts per variant and 132 in total, including LFM2.5's runs without thinking.

All the scripts are public, exactly as each model wrote them: their index has the status of each one and the file path, for example a successful script for the network task. The test program is public too. The status values in the index are in Romanian: corect means correct, eroare means error.

The results

For each of the ten model variants, two bars: correct answers to problems out of 36 and correct scripts out of 12. gpt-oss:20b has 36 and 11, qwen3:30b-instruct 33 and 11, qwen3:8b with thinking 36 and 7, qwen3:30b with thinking 36 and 7, qwen3:4b with thinking 36 and 6, the 3-bit variant 36 and 5, qwen3:8b without thinking 30 and 4, qwen3:4b-instruct 34 and 1, lfm2.5 28 and 0, granite 4 and 0
The blue bars are almost all full. The orange ones are not.
Model Mode Correct scripts extensions log inactive cidr Seconds per script
gpt-oss:20b thinking 11 of 12 3/3 3/3 3/3 2/3 59
qwen3:30b-instruct none 11 of 12 3/3 3/3 3/3 2/3 5
qwen3:8b thinking 7 of 12 3/3 3/3 1/3 0/3 44
qwen3:30b thinking 7 of 12 3/3 2/3 2/3 0/3 223
qwen3:4b thinking 6 of 12 2/3 1/3 3/3 0/3 65
Qwen3-30B-A3B Instruct, 3-bit none 5 of 12 1/3 1/3 3/3 0/3 4
qwen3:8b none 4 of 12 1/3 0/3 3/3 0/3 2
qwen3:4b-instruct none 1 of 12 0/3 0/3 1/3 0/3 2
lfm2.5:8b-a1b thinking 0 of 12 0/3 0/3 0/3 0/3 6
granite3.1-moe:3b none 0 of 12 0/3 0/3 0/3 0/3 3

The last column is the median generation time. The network task was solved by 4 scripts out of 33, all written by the top two models.

With only 12 scripts per variant, a difference of one script means nothing. The big differences are the ones to remember: 11 versus 5, 11 versus 1.

How the models fail

Segmented bars with the fate of each variant's 12 scripts: correct, runs with wrong output, runtime error, and no script or not run; in total, for the ten variants, 52 correct, 21 with wrong output, 26 with errors and 21 with no script or not run
Each bar holds 12 scripts. The color shows how the run ended.

Of all 132 scripts, 53 gave the correct result. The rest fall into five kinds of failure.

Commands and parameters that do not exist. lfm2.5:8b-a1b used Format-String and Convert-Csv, two commands PowerShell does not have. qwen3:8b wrote Measure-Object -Count, a parameter that does not exist. The script stops at the first such line:

Format-String : The term 'Format-String' is not recognized as the name of a cmdlet

Syntax from another version. Although we asked for PowerShell 5.1, LFM2.5 several times wrote syntax that exists only from PowerShell 7 on, such as the ?? operator. On an ordinary Windows machine, the script does not even start.

Scripts that run and give a wrong result. This is the most dangerous failure, because no error appears. It happened with 22 scripts out of 132. Two models sorted the extensions by number of files, not by size. qwen3:8b with thinking compared the date from the CSV, as text, with a calendar date, and the script did not list a single inactive user. qwen3:4b counted the errors with the expression below and printed “True” instead of numbers:

$counts[$date] = ($counts[$date] + 1) -or 1

One wrong letter. qwen3:30b with thinking thought for 3,207 tokens, almost three minutes, and then wrote Import-Csv utilisatori.csv. The file was called utilizatori.csv (Romanian for “users”). LFM2.5 looked four times for applicatie.log instead of aplicatie.log.

32-bit arithmetic. The network task needs bitwise operations on unsigned numbers, and PowerShell's ordinary integers are signed. Even gpt-oss:20b got it wrong once here:

Cannot convert value "4294967040" to type "System.Int32"

Thinking helps, until it runs out of budget

With qwen3:8b, the only model we can compare directly, thinking raised the score from 4 to 7 correct scripts. At 4B, the thinking variant wrote 6, and the non-thinking one, 1.

With the large model, things go the other way. qwen3:30b-instruct, without thinking, wrote 11 correct scripts at 5 seconds each. qwen3:30b, with thinking, wrote 7 at 223 seconds each. Its 12 scripts took 50 minutes in total, compared with 2 minutes.

The reason is the budget. In 11 cases, the model thought up to the 7,168-token limit and never got around to writing the script. Nine of them are on the network task, where all three Qwen3 models with thinking went round in circles on the bit arithmetic without reaching a conclusion.

We chose the token limit ourselves. With a higher limit, some might have finished; we did not test that. But on our PC, 7,168 tokens already means six and a half minutes of waiting with the 30B model.

3-bit quantization hurts code most of all

Qwen3-30B-A3B Instruct at 3 bits is the same model as qwen3:30b-instruct, compressed from 18.6 to 14.7 GB. The compression lets it fit on computers with 16 GB of memory.

Qwen3-30B-A3B Instruct 4-bit 3-bit
Correct problems out of 36 33 36
Correct scripts out of 12 11 5

On the problems, the compressed version came out even slightly better. On the scripts it lost more than half. Its mistakes are typos, not reasoning errors. Twice it closed a parenthesis with a curly brace:

"$($_.Name};$($_.Count)"

Other times it put an extra dot before the extension and printed ..log instead of .log. In a logic problem, a small slip does not change the answer. In a script, a single wrong character stops it.

Fast does not mean good

The two models that came out fastest in the hardware article are last here. lfm2.5:8b-a1b generates 210 tokens per second on the PC and did not write a single correct script out of 12. With thinking switched off, it wrote one out of 12. granite3.1-moe:3b generates 229 tokens per second and has 4 correct answers out of 36 on the problems.

Part of the explanation is language. We wrote all the tasks in Romanian. The model card for LFM2.5-8B-A1B lists ten languages, and the one for Granite 3.1, twelve. Romanian is not among them. We did not repeat the tests in English, so we do not know how much of the gap comes from the language and how much from the model.

For a company that works in Romanian, the practical conclusion stays the same: a model that does not understand the language well is not an option, however fast it writes. LFM2.5 also has its own license, which limits commercial use to companies with annual revenue under 10 million dollars.

Nine scripts we did not run

Before running anything, we read all 132 scripts. An automatic filter held back the ones that contained deletions, writes to files, network calls or paths outside the working folder. Nine scripts were left unrun:

  • one Granite script made DNS lookups for the IP addresses in the task;
  • two Granite scripts wrote the result to files on C:\, although we had asked for it to be printed;
  • one Granite script started Start-Transcript over the log file it was only supposed to read;
  • four Granite scripts read from made-up paths, such as C:\path\to\your\directory;
  • one LFM2.5 script used Set-Item with a wrongly built path.

None of them was destructive. But the first version of our filter had missed the DNS lookup; we found it only by reading the script. A tenth script, from qwen3:4b-instruct, got past the filter and ate memory until the 30-second limit stopped it: it multiplied a string by 256 instead of a number, and PowerShell repeats the string.

A script written by a model gets read before it is run, every time. Not because the model wants to break something, but because it does not know where it is running.

How to test a model before relying on it

  1. Pick three or four tasks from your real work, with input data you know and a result you can check.
  2. Ask for each task at least three times. The same model gives different answers to the same request.
  3. State the exact version of the environment: “Windows PowerShell 5.1”, not “PowerShell”.
  4. Read the script before running it. Look for commands that delete, write, download or leave the working folder.
  5. Run it in a test folder, on a copy of the data, and compare the result with the known one.
  6. Pay special attention to the scripts that give no error. A plausible, wrong result is the easiest to miss.
  7. With thinking models, watch how many tokens they use. If the answer comes back empty, the model ran out of budget.

Where this does not apply

  • Small sample. 12 scripts per variant show the big differences, not fine-grained rankings. There is no real difference between 7 and 6.
  • Four tasks, one language. The results are for PowerShell 5.1. In Python, which is far more present in training data, the small models might do better. We did not measure it.
  • Tasks in Romanian. Two of the models do not list Romanian among their supported languages.
  • One quantization per model, except for Qwen3-30B-A3B. We do not know how the other models behave at 3 or 8 bits.
  • Default settings. We did not tune the temperature or other options for code.
  • Strict checking. A script with the right output but one extra line was counted as wrong. We ignored only the spaces around the separator.

How we work

Brio Argus, the assistant that answers from a company's internal documents, can work with several local models through Ollama and has a benchmark across models. This test reinforced a rule we already followed: measurements are repeated on the client's machine, with the client's tasks, before any recommendation.

For us, the conclusion of this test is that a good score on general problems does not tell you whether the model does well the job you choose it for. You choose the model on the real task, and you check what it writes.

If you want to use a local AI model for scripts, reports or answers from documents, send us two or three tasks you do often. We will tell you how we would test them and which model is worth trying on the hardware you have.

Frequently asked questions

Which local model writes the best PowerShell scripts?

In our test, gpt-oss:20b and qwen3:30b-instruct each wrote 11 correct scripts out of 12. The first is 14 GB and needed almost a minute per script. The second is 19 GB and answered in 5 seconds. Models under 10 GB wrote at most 7 out of 12.

Can I trust a script written by a local AI model?

Not without reading and testing it. Of 132 generated scripts, 53 gave the correct result, and 22 ran without any error and gave a wrong result. Nine contained operations we had not asked for, such as disk writes or DNS lookups, and we did not run them.

Does thinking mode help with writing code?

With small models, yes: qwen3:8b went up from 4 to 7 correct scripts out of 12. On hard tasks it can backfire: in 11 cases, the models thought up to the 7,168-token limit and wrote no script at all. qwen3:30b-instruct, without thinking, was better and 40 times faster than its thinking variant.

Is a model quantized to 3 bits worth it?

It depends on the task. Qwen3-30B-A3B at 3 bits answered correctly in all 36 runs of the logic problems, but wrote only 5 correct scripts out of 12, compared with 11 at 4 bits. For code, where one wrong character stops everything, the extra compression cost a lot.

Why did the fastest model do so badly?

lfm2.5:8b-a1b generates 210 tokens per second, but it made up commands, used syntax from another PowerShell version and got file names wrong. One likely cause is language: the model card does not list Romanian, and our tasks were in Romanian. We did not repeat the test in English.

Document anonymization solutions: what exists and how to choose

Manual redaction, open-source library, cloud API or on-premise app with local AI: what each document anonymization solution does and how to choose.

Read the article

Ollama on five computers: which model fits and how fast it runs

The same AI models run through Ollama on a PC with an RTX 3060 Ti, a laptop, a Mac mini M2, a mini PC and a server: what fits, how fast, which settings matter.

Read the article

How an LLM thinks: Qwen3's thinking mode, measured in Ollama

What “reasoning” means for a language model, how Qwen3 learned to think, and what we measured on 12 problems, with and without thinking, in Ollama.

Read the article

Want to talk about your company’s IT?

Tell us what you are dealing with and we will reply with a concrete recommendation, with no obligation.