PowerShell Formatter
Re-indent a PowerShell script so functions, foreach loops and try/catch blocks nest properly again, one level per brace.
Input
Output
What is PowerShell?
PowerShell is a cross-platform task automation and configuration management framework from Microsoft. It includes a command-line shell and scripting language built on .NET, widely used for Windows administration and DevOps automation. You can learn more on Wikipedia, and the community-maintained PowerShell source is on GitHub.
What it changes is deliberately narrow. Each line is trimmed and pushed in four spaces for every {, ( or [ still open above it, counting brackets anywhere on a line but never inside a string or a comment, so "{not a brace}" and a one-line if ($x) { $y } leave the depth alone. A line that starts with a closer steps back out. Spacing inside a line is left alone, comments are indented with the code around them, and a here-string (@" ... "@) is copied exactly, because moving its closing "@ off the first column breaks the script. That is usually enough to make a script pulled from the PowerShell Gallery or a colleague's gist readable again.
How to Use
Paste your PowerShell script
Drop the script into the left pane, or Upload a .ps1, a .psm1 module or a .psd1 manifest. Sample loads a deploy script with a param() block, a Write-Log helper and a foreach dependency check, every line flush left.
Read the formatted script
The right pane updates as you type: 4 spaces per level, blank lines squeezed to one, trailing spaces gone. It does not add spaces around = or after keywords, so foreach($user in $users){ keeps its own spacing.
Copy or download
Copy puts the re-indented script on the clipboard. Download always saves it as script.ps1, so rename the file if what you pasted was a .psm1 module.
Formatting Example
Example: Format a user creation script
Unformatted input:
$users=@("mbrennan","ihalvorsen","achen")
foreach($user in $users){
New-LocalUser -Name $user -NoPassword
Add-LocalGroupMember -Group "Users" -Member $user
Write-Host "Created: $user"
}Formatted output:
$users=@("mbrennan","ihalvorsen","achen")
foreach($user in $users){
New-LocalUser -Name $user -NoPassword
Add-LocalGroupMember -Group "Users" -Member $user
Write-Host "Created: $user"
}Frequently Asked Questions
Is PowerShell cross-platform?
Yes. PowerShell Core (v6+) runs on Windows, macOS, and Linux. Windows PowerShell (v5.1) runs only on Windows.
What indentation does PowerShell use?
While no official standard exists, 4 spaces is a widely used convention in PowerShell scripts. Microsoft's PowerShell development guidelines cover best practices for script style.
Can I format .psm1 module files?
Yes. PowerShell module files (.psm1) and script files (.ps1) use the same syntax and are both supported. Published modules are available on the PowerShell Gallery.
Is my PowerShell code safe when I use this tool?
Yes, completely. All formatting happens locally in your browser: your script is never sent to any server. Your PowerShell code stays private and secure at all times.