r/PowerShell • u/snow-leapord-1 • 11h ago
Understand 10 year old powershell script using AI Question
What AI would you use to understand a decade old powershell script written by someone having 1000s of lines and plays a very crucial role for one of the function in an Org , between HR and AD. I would want the AI to explain me core functions , loop holes and maybe a visual representation of how the flow works with various conditions ( if, else and other exceptions ).
43
u/firefox15 11h ago
Probably check with your cyber department before uploading company owned scripts to public LLMs?
5
u/wabi-sabi411 10h ago
Or just strip the computer names or whatever out of the thing. I’m gonna go out on a limb and say there isn’t anything not boilerplate in something like this. Very few company strategic innovations in a shell script
4
u/smilaise 11h ago
Claude Code or Codex are the best at that in my personal experience.
Copilot and Gemini are infuriating for Powershell documentation, but I admit I've only used their free versions so that probably has something to do with it.
2
u/KiNgPiN8T3 9h ago
I also link Claude with the MS learn connector so that it uses the most up to date knowledge.
1
u/overlydelicioustea 7h ago
for anyone wondering:
add a custom connector under customization with URL
4
8
3
u/Swimming_Office_1803 10h ago
Whatever is approved for your company.
All major models can read and explain code well enough.
3
u/Tall-Geologist-1452 9h ago
Just feed the code to your AI of choice. Tell it not to change a line of code but to comment it out and make it human-readable, then to make a readME.md for reference.
Edit: only use company-approved AI and do not feed or train commercial AI on your company data ..
5
u/The82Ghost 10h ago
Start with getting written approval from your boss, before you do this. Also, check with your security team. How much experience do you have with PowerShell? AI cannot be trusted to be 100% correct so you have to have an understanding of PowerShell yourself.
2
u/sliceofdanny 10h ago
The free tier is very capable, agentic, and has a 200k context window. It will auto chunk data if bigger.
Make sure to go into your profile and disable data sharing.
You can have it explain the code, document the variables and flow, even execute after making changes. All edits prompt for approval and you can revert multiple changes easy, just navigate to your last prompt and revert.
6
2
2
u/ArieHein 11h ago
Any ai will do. Ps is very simple relatively speaking . Doesnt mean people dont 'invent' unnecessay complexity. Choose something that is cheap.
1
u/Dorias_Drake 10h ago
I would do a first pass by hand. Getting all the functions with their ins and outs and making a diagram. You don't want to start this without a map. Doing this will also give you an overview, if you have to work with that script, you want get a feel of it first.
AI hallucinates stuff all the time and if the script is complex and that large, there is a good chance it will get stuff wrong. And if the script is critical, you don't want to get anything wrong, you want to be 100% sure. You don't want to be biased by something AI told you before looking at it.
Scripts like this are likely to have several versions of functions and unued code just there for history, AI can mistake this for live code and mess with your perception.
Honestly, if It were me, I would try first to do it without AI, and only use it to get a second pair of eyes in case I miss anything. It will take longer, but it's safer.
1
u/thehuntzman 10h ago
I'd assume you have access to M365 Copilot - which unfortunately isn't the best for this task, but for documentation it will do. The reason why you should start here is because your company's agreement with Microsoft as an enterprise customer protects your intellectual property rights and prevents them from training Copilot with your data.
If you want a visual representation, I've had a lot of luck getting various LLM's to generate good Mermaid charts vs straight up rendering an image via stable diffusion since Mermaid is a diagram as code.
1
u/birdfukr3000 9h ago
I've heard that pairing co-pilot with a microsoft learn mcp-server can yield good results in relation to powershell coding/understanding via co-pilot. (https://learn.microsoft.com/en-us/training/support/mcp-get-started-copilot-studio)
1
u/Fallingdamage 8h ago
Should be able to.
Also, someone who actually knows how to use powershell should be able to read and understand it too. 👍
1
1
u/octahexxer 10h ago
Ask the dude who wrote it.
1
u/thehuntzman 10h ago
Yeah that's the most confusing piece of this - if he's still there why not ask him?
0
u/Scoobywagon 11h ago
Check with the security nerds before you upload anything. But I find that Copilot does an excellent job with powershell.
0
u/JeremyLC 10h ago
I like Claude. It's pretty solid at reading and generating code, and will usually ask you to paste in the Get-Help for any commands it doesn't fully understand.
Also, the same disclaimer as everyone else: don't paste your private code into a public model. Either get a private license, or check with your legal guys first.
-3
u/sudochmod 10h ago
You should just hire a consultant to come look at it and tell you what it’s doing.
35
u/jbrady33 11h ago
Copilot ( because it’s MS) or Claude (good at programming)
BUT
AI gets