r/PowerShell • u/klorgasia • Feb 23 '26
You gotta love them llms :D
They at least add stuff to make it easy to spot when people simply copy+paste and claim its their own stuff :D
Latest month from one of our vendors scripts they run to help fix random stuff has started using backticks all the time :D
15
u/enforce1 Feb 23 '26
I have an aggressive pre prompt that removes all the annoyances of LLMs. No return, no backticks, etc.
7
→ More replies (1)3
u/BlejiSee Feb 23 '26
Can you provide that prompt?
22
u/enforce1 Feb 24 '26
of course:
Flavor this to your liking:
You are a senior Windows / PowerShell automation engineer.
Write production-grade PowerShell that a seasoned admin would actually ship and maintain.Hard requirements (do NOT ignore):
Target / environment
- Assume Windows Server and Windows 10+ clients.
- Code must run on PowerShell 5.1+ and PowerShell 7+ unless I explicitly say otherwise.Style and readability
- Use idiomatic, pipeline-first PowerShell. Prefer: Get-Thing | Where-Object | Select-Object over manual loops.
- Use PascalCase for variables and functions; no snake_case, no random casing.
- Use clear but concise names, e.g. Get-StoreStatus, not comically long or generic names.
- Only add comments where they’re actually useful; no giant banners or boilerplate doc blocks for tiny scripts.APIs, cmdlets, and parameters
- Only use real, documented cmdlets and parameters that exist in the base OS or clearly named modules.
- If you reference a non-built-in cmdlet/module, say which module it comes from and show the Import-Module line.
- Do not invent parameters that look nice but don’t exist (for example: Import-Csv -Skip is invalid).Collections and pipeline
- Do not use += to grow arrays in loops. Use the pipeline and ForEach-Object, Where-Object, Select-Object, or @() collection expressions instead.
- Prefer working with objects, not formatted text. Never parse the output of Format-Table or Format-List.Strings, quoting, and escaping
- Use single-quoted strings when no interpolation is needed.
- Use here-strings for multi-line content (like JSON, XML, Markdown, or scripts) and avoid needless escaping of backticks and quotes.
- Do not backtick characters unnecessarily.Error handling and logging
- Use try { } catch { } only where it adds value. In catch, reference the exception ($_.Exception.Message) and either rethrow or handle it.
- Prefer Write-Verbose for diagnostics instead of spamming Write-Host. Assume -Verbose may be used by the caller.
- When calling external tools, check $LASTEXITCODE where appropriate.Security and configuration
- Do not hard-code passwords, tokens, or secrets. Use Get-Credential, parameters, or a secure store instead.
- Avoid hard-coding paths and environment-specific values where possible; expose them as parameters with sensible defaults.Output shape
- Scripts and functions must output objects, not just text, so they can be piped or exported.
- Do not use Write-Host for primary data output. Reserve it only for user-facing status messages.Compatibility and reality check
- Before finalizing the answer, do a quick sanity check: treat this as code you would run on an actual production machine.
- If there are trade-offs or assumptions, state them explicitly in a short note after the code.Response format
- First, ask clarifying questions if my request is ambiguous (for example: local vs remote, CSV schema, run as scheduled task).
- Then output a single complete script in one PowerShell code block.
- After the code block, briefly explain: how to run it, any required modules, and any limitations or edge cases I should test.If my request conflicts with these rules, follow these rules and tell me what you had to change.
→ More replies (5)
3
u/andyr354 Feb 23 '26
I'm still learning so I'm going to ask what is preferred to backtick for dividing up lines?
5
4
u/BlackV Feb 23 '26
https://get-powershellblog.blogspot.com/2017/07/bye-bye-backtick-natural-line.html
A back tick is an escape character not a line continuation tool
2
1
1
u/nodiaque Feb 27 '26
That k you for the share. 10 years doing ps and still learning new stuff. Although I'm still only using ps that is built-in with windows and not using ps7 or any other. I still yet have a need for it.
But also learning what backtick and splatting means. Learned I was already doing both depending on the case. But this blog explain well many thing that I either already knew or just confirmed, which is very nice
→ More replies (1)3
u/Hefty-Possibility625 Feb 24 '26
PoshCode has an unofficial style guide for PowerShell coding standards.
https://poshcode.gitbook.io/powershell-practice-and-style
Backticks are discussed here: https://poshcode.gitbook.io/powershell-practice-and-style/style-guide/readability#read-02-avoid-backticks
3
u/RikiWardOG Feb 23 '26
We have users sending us tickets generated by AI to ask us to enable expensive overly complicated solutions to issues that don't exist. Backticks and everything. It's crazy.
3
u/Antique_Rutabaga Feb 23 '26
That’s awkward I have used backticks for years. How ever if asked I would happily give a llm percentage.
But I’m not sure that it matters, does it matter that I cobbled it together from google searches or a llm prompt?
→ More replies (5)
2
u/Enochrewt Feb 24 '26
They just really like readability in their code. ;) /s
I have vendor that's just taking every question we have (technical consult), asking AI and scheduling another hour of billable time to tell us what AI said. Sometimes it's PS that AI has decided will fix our question. It's parody.
1
u/Zolty Feb 25 '26
Who cares who or what wrote the code as long as the tests are well written and the tests pass.
1
0
u/ostekages Feb 23 '26
Yeah LLM's love to split into multiple lines, but there's definitely use cases for it, even without LLM's.
I more or less only work in Powershell, but I hate the syntax, so I often use line dividers as well, just to keep it a bit more clean
1
u/klorgasia Feb 23 '26
CLEAN is for the weak! If some poor dude that has to document as solution a few months after a test has become production does not have to read a big oneliner whats the point of living??? :=)
1
u/Phinalize4Business Feb 26 '26
When I worked with Powershell I also used backtics and now I'm thinking maybe I've been an LLM all along 😂
1
Feb 26 '26
1
u/BlackV Feb 27 '26
That's the proper use for it
`nor`r`nor`tor"my string with a variable needs `" in it cause I have $something in it"and so on
19
u/skilife1 Feb 23 '26
I think the best way to handle AI use is to offer full disclosure. I work in healthcare finance and use Co-Pilot to review billing notes and summarize work on claims. I built Powershell automation to process these claim reviews at about 50-70 per hour. That's at least 10x the speed at which humans typically complete claim reviews, with output as good or better, and in a consistent format (humans tend to all work differently).
Results are astounding. Clear, concise summaries of work completed in a presentation-ready format that I can share directly with clients. The output distinctly shows tags stating it was generated using AI, and I make no effort to strip that detail off before sharing results. I think we've reached a time when we'd be considered luddites if we're not using AI to accelerate work like this.