PowerShell Script Generator Prompt
Generate a readable PowerShell script from a verified task, environment, inputs, and safety constraints, with validation, WhatIf support, testing, and rollback guidance.
Prompt Template
You are a senior PowerShell engineer generating a script only from the task, environment, and exact targets I supply. Resolve material ambiguity before writing mutating code. Prefer object-based pipelines, literal paths, least privilege, idempotent operations, previews, and readable functions over compressed one-liners. Task and success criteria: [details] Operating system and version: [Windows, macOS, Linux, exact version] PowerShell edition, version, and host: [details] Working directory: [exact verified path] Inputs, formats, and representative sanitized examples: [details] Expected outputs and destination paths: [exact details] Files, registry keys, services, accounts, cloud resources, hosts, or processes in scope: [exact identifiers] Targets that must never be touched: [list] Existing state and read-only inspection output: [paste] Required cmdlets, modules, providers, and verified versions: [list] Permissions, execution policy, and approved elevation: [details] Remoting, network, tenant, subscription, and authentication boundaries: [details] Concurrency, file-size, runtime, and cross-platform constraints: [details] Path case, provider, wildcard, encoding, newline, culture, and time-zone behavior: [details] Secrets and personal data handling: [placeholders or approved secret store; never paste values] WhatIf, Confirm, or preview requirement: [details] Logging, transcript, structured output, and exit-code requirements: [details] Backup, rollback, and interruption requirements: [details] Existing script, module, tests, or style rules: [paste or none] Provide: 1. A requirements inventory separating verified inputs, assumptions, unresolved blockers, side effects, and success checks. 2. Read-only commands to confirm the PowerShell version, modules, providers, paths, permissions, connectivity, and target scope. 3. One complete formatted script with comment-based help, parameter validation, meaningful functions, strict error handling, and explicit output behavior. 4. SupportsShouldProcess, WhatIf, and Confirm behavior for any material write, deletion, permission change, service action, remote call, or cloud mutation. 5. Literal-path handling and explicit wildcard behavior, plus safe temporary-file and cleanup logic when needed. 6. Object-based pipeline logic that avoids parsing formatted display text; explain serialization, encoding, culture, and time-zone choices where relevant. 7. Pester tests or a practical test plan using a temporary fixture or non-production scope, including empty input, spaces, duplicate runs, partial failure, and interruption. 8. Validation commands that confirm the requested result without relying only on the script's success message. 9. Backup and rollback instructions before material changes, with limits stated when rollback is impossible. 10. A final audit for unresolved placeholders, injection, broad recursion, wildcard expansion, provider confusion, secret leakage, unapproved elevation, remoting scope, destructive defaults, and platform incompatibility. Do not invent paths, module behavior, command output, installed tools, credentials, tenant state, registry keys, or successful results. Never emit destructive recursion against an unresolved variable, wildcard, user profile, drive root, workspace root, subscription, or unverified remote scope. If a concrete target or policy choice is missing, ask for it instead of generating runnable mutation code.
Example Output
Requirements to Resolve
Replace the directory placeholder with an exact verified path before running. This example only lists matching files and changes nothing.
$inputPath = '[VERIFIED_DIRECTORY]'
$cutoff = (Get-Date).AddDays(-30)
if (-not (Test-Path -LiteralPath $inputPath -PathType Container)) {
throw 'The verified input directory does not exist.'
}
Get-ChildItem -LiteralPath $inputPath -File -Filter '*.log' |
Where-Object { $_.LastWriteTime -lt $cutoff } |
Select-Object FullName, LastWriteTime, Length
Validation
Run the read-only query against a temporary fixture containing spaces, recent files, and older files. Inspect every returned FullName before adding a separate mutating function with SupportsShouldProcess.
Safety Note
No deletion, elevation, remoting, registry change, or successful result is claimed.
Tips for Best Results
- ๐กProvide the exact PowerShell edition, module versions, providers, and target scope.
- ๐กRequire SupportsShouldProcess and test WhatIf output before any material mutation.
- ๐กUse object properties and literal paths instead of parsing display text or relying on wildcard expansion.
Frequently Asked Questions
What is the PowerShell Script Generator Prompt prompt?
Generate a readable PowerShell script from a verified task, environment, inputs, and safety constraints, with validation, WhatIf support, testing, and rollback guidance. It's a free ChatGPT prompt template from our Coding collection โ copy it, fill in the bracketed variables, and paste it into your AI tool.
Which AI tools work with this prompt?
It's written and tested for ChatGPT, Claude and Gemini. Any AI assistant that accepts free-form text prompts will handle it well.
How do I customize this ChatGPT prompt?
Replace the bracketed variables โ such as [details], [Windows, macOS, Linux, exact version], [exact verified path] โ with your own details before running it. Provide the exact PowerShell edition, module versions, providers, and target scope.
Is this prompt free to use?
Yes. Every prompt on PromptAtlas is free to copy, customize, and use โ no signup required.
Related Prompts
Code Review Assistant
Get a thorough, senior-level code review with actionable feedback on quality, security, performance, and best practices.
Debugging Detective
Systematically debug errors and unexpected behavior with root cause analysis and fix suggestions.
Code Refactoring Advisor
Transform messy, complex code into clean, maintainable, well-structured code with clear explanations.