Q&A
PowerShell Meets Practical AI: Aleksandar Nikolić on Smarter Scripting Workflows
Ahead of his TechMentor session at Microsoft HQ, PowerShell expert Aleksandar Nikolić explains how AI tools like GitHub Copilot can help admins write, refactor, test and document scripts faster -- without replacing hard-earned PowerShell expertise.
AI is quickly reshaping the way administrators approach scripting, but for experienced PowerShell users, the real promise is not automation without expertise -- it's automation that amplifies it.
In this Q&A, Aleksandar Nikolić, a Microsoft MVP, discusses how tools such as GitHub Copilot and MCP servers can remove repetitive friction from everyday scripting while keeping human judgment at the center. His upcoming TechMentor session, "AI Tools for Better PowerShell Scripting" (taking place in August at Microsoft Headquarters), will show attendees practical ways to use AI to write, clean up, document, validate and improve PowerShell scripts. As Nikolić notes, AI can generate code quickly, but seasoned admins are still essential for catching bad assumptions, missing error handling and environment-specific risks.
And for more on this topic from Nikolić, join us for his upcoming session at this year's TechMentor & Cybersecurity Live! Register by June 5 to save $400!
Redmondmag: For experienced PowerShell users, what does AI change about the scripting workflow without replacing the need for core PowerShell knowledge?
Nikolić: AI doesn't change what PowerShell knowledge
is, it changes how much of your time actually goes toward applying it. Before tools like GitHub Copilot, a significant chunk of every scripting session went toward things you already knew how to do: looking up the exact parameter name, writing the same code for the hundredth time, hunting through docs for the right syntax. Copilot handles that overhead, which means your time shifts toward the work that actually requires judgment -- architecture decisions, edge cases and what happens when this script runs against a production environment at 2 a.m. and something unexpected goes wrong.
What that means in practice is that your years of PowerShell experience become
more valuable, not less. AI generates fast and confidently -- but it also confidently generates code that uses a deprecated cmdlet, skips error handling entirely or ignores the specific constraints of your environment. It takes a seasoned admin to catch those things before they become incidents. Your knowledge is the steering wheel; Copilot is the engine. That's exactly the relationship we dig in during my TechMentor session, where we look at how to set up AI tooling so it's working for you and amplifying your expertise rather than working around it.
What are some examples of everyday PowerShell tasks where AI can save meaningful time for administrators?
The biggest time savings aren't from dramatic use cases -- they're from all the small friction that adds up across a day. Scaffolding an advanced function used to mean either typing the same `[CmdletBinding()]`, `param()` and `begin/process/end` blocks from memory or stopping to look up the pattern again. With GitHub Copilot, you describe what the function should do and it produces a complete, idiomatic scaffold in seconds. Same story for module structure -- getting the folder layout, the manifest and the dot-sourcing pattern right every time without breaking flow. Copilot CLI takes this even further for command-line tasks, letting you describe what you want to accomplish in plain language and get the right PowerShell command back without leaving the terminal.
The Pester story is equally compelling. Writing tests for an existing function is one of those tasks everyone knows they should do and almost no one finds time for because it's tedious and the payoff feels distant. AI turns it into a five-minute task: describe the function's behavior, ask Copilot to generate a test suite, review and adjust. Refactoring long PowerShell commands to use splatting is another quick win that makes code dramatically more readable, and Copilot can both spot where it should be applied and execute it cleanly. The common thread is that AI absorbs the mechanical work so you stay focused on the parts that actually require you.
AI can produce confident but incorrect code. What are the most common failure modes you see when AI suggests PowerShell scripts?
The failure mode that catches people off guard most often isn't the one where the script crashes immediately. It's when the script runs fine but does the wrong thing. Missing error handling is the biggest culprit. AI tends to generate happy-path code: everything works, the cmdlet succeeds, the object comes back as expected. There's no `-ErrorAction Stop`, no `try/catch`, nothing that handles what happens when the target system is unavailable or the expected object doesn't exist. In a lab it looks perfect. In production it fails silently or partially, and you're left debugging a script that "worked" yesterday. Hallucinated cmdlet parameters are the other high-frequency failure -- AI invents a parameter name that doesn't exist, or borrows one from a different cmdlet or a different version of a module. The code looks right to anyone who doesn't know the cmdlet well, which is exactly who's most likely to be relying on AI-generated code in the first place.
Deprecated syntax is a quieter problem, like `Get-WmiObject` instead of `Get-CimInstance` (superseded in PowerShell 3.0 and removed entirely in PowerShell 7), or patterns from older PowerShell versions that signal to every reviewer that this code hasn't been touched in years. And the failure mode that stings experienced teams most is something subtler: AI ignores the established patterns in your existing codebase. It has no idea you always use a particular error-handling wrapper, a specific naming convention or a preferred way to handle pipeline input unless you explicitly tell it. That's precisely what Copilot's custom instructions and shareable agent skills are designed to address, and it's one of the most impactful customizations you can make.
How can AI help admins clean up older scripts that may work, but are difficult to maintain, read or hand off to another team member?
Older scripts present a fascinating challenge because the problem isn't that the code doesn't work. It's that no one can quickly understand how it works or why certain decisions were made. The most effective approach is bringing the script into GitHub Copilot Chat with explicit context about your team's current standards: the patterns you use, your naming conventions, how you handle errors. From there you can ask Copilot to do a structured review to identify inconsistencies, organize the code into logical regions with clear headers and rename variables so they tell a story instead of relying on institutional memory to decode them. The result is code that the person inheriting it can actually read on a Monday morning without needing a forty-minute walkthrough.
What makes this genuinely powerful for team handoffs is custom instructions. Rather than cleaning up a script generically, Copilot cleans it up your way so the result looks like it belongs in your codebase. You can also use AI for drift detection: point it at an entire module and ask it to flag everything that deviates from your standards. You get a prioritized, specific list of what to address rather than a vague sense that "this code needs work." For scripts that have been in production for years without a documented owner, that kind of structured audit is often the difference between a script that gets quietly avoided and one that actually gets maintained.
For beginners, how can AI be used as a learning partner without becoming a crutch that prevents them from understanding the language?
The single most important habit I recommend to beginners is using AI in planning mode before it writes a single line of code. Describe what you're trying to accomplish and ask Copilot to outline the approach -- what cmdlets would be involved, what the data flow looks like, what edge cases are worth thinking about. That conversation forces you to engage with the logic of the solution before you see the code. When the code does appear, you're in evaluation mode rather than acceptance mode. Then ask it to explain what it generated, step by step. That explanation loop is where actual learning happens, and it's a habit that pays dividends even once you're experienced because explaining code out loud, even to an AI, surfaces assumptions you didn't know you were making.
The Microsoft Learn MCP Server is a valuable companion here. When AI explains a cmdlet or a concept, you can immediately ask it to pull the official documentation and verify what it told you. That habit of cross-referencing builds the instinct to not take AI output at face value, which is exactly the instinct you want beginners to develop early. The other practice I push hard: for anything non-trivial, write your best attempt first, then ask Copilot to review it. You'll learn far more from that review -- seeing what it changes and why -- than from reading code AI produced without your input. Use AI to help you think, not to think for you.
How can AI help improve PowerShell documentation, comments, and examples so scripts become more useful across a team?
Comment-based help is the natural starting point. AI can read a function's code, understand what the parameters do and generate a complete `Get-Help`-compatible block in seconds. For a module with twenty undocumented functions, that's a meaningful amount of time recovered in an afternoon. But the more interesting team-scale story is about consistency, not just coverage. AI-generated help blocks vary in quality and style depending on how you ask, which means you can end up with documentation that's technically present but reads like it was written by different people on different days -- because it effectively was.
The solution that actually scales is shareable agent skills and templates: a standardized documentation workflow your whole team runs whenever they write a new function. Everyone gets the same structure, the same level of detail, the same voice -- and new team members follow the same process from day one. Beyond generation, AI can audit your existing codebase for drift: flag functions with missing `.EXAMPLE` sections, inconsistent parameter descriptions, or help blocks that no longer match the actual parameters after a refactor. That kind of drift detection is tedious to do manually and almost never happens as a result; AI makes it something you can run as a routine check. Documentation stops being an individual habit that some people have and some don't, and starts being a team standard that's actually enforced.