PowerShell Script Formatter and Checker
Re-indent PowerShell scripts, align hashtable values, correct the casing of cmdlets, keywords and operators, and get PSScriptAnalyzer-style warnings for each script.
Funziona nel tuo browser. I tuoi file non lasciano mai il dispositivo. Scopri come verificarlo
…
Come si usa
- 1Add scripts
Paste a script or open .ps1, .psm1 and .psd1 files.
- 2Choose a style
Pick OTBS, Stroustrup or Allman and set the indent width.
- 3Set casing and aliases
Decide whether to fix casing and expand aliases.
- 4Review changes
Read the diff and the PSScriptAnalyzer-style warnings.
- 5Jump to problems
Click a line number to place the cursor on that line in the source.
- 6Download
Apply the result and download the script, a ZIP or a .patch.
Informazioni su questo strumento
PowerShell is unusually hard to format because the same characters mean different things in expression mode and command mode: a dot can be member access or dot-sourcing, a dash can start an operator, a parameter or a subtraction, and a brace on the next line can turn a script block argument into a separate statement. This formatter is careful about that. Its tokenizer reads variables such as $env:Path and ${my var}, splatting with @params, subexpressions $( ), array and hashtable literals @( ) and @{ }, -operators and -Parameters, backtick line continuations, here-strings @" "@ and @' '@, and <# #> comment blocks. Spacing is only normalised where it is safe: around assignments, pipes and commas, inside braces, and after keywords such as if, foreach and switch. Everything else keeps the spacing you wrote, so command arguments are never glued together or split apart. The formatter re-indents blocks, parameter lists and hashtables, indents the lines that continue a pipeline after a trailing pipe, aligns the = signs of multi-line hashtables the way the AlignAssignmentStatement rule does, and puts else, elseif, catch and finally on the same line as the closing brace. Cmdlet names are corrected to their canonical casing, as are calls to functions declared in the same script; keywords and comparison operators become lower case.
Script checks
The checks follow PSScriptAnalyzer rule names so you can look them up. Aliases such as gci, ls, % and ? are reported with their full cmdlet names, and an option expands them for you. Functions whose verb is not on the approved list from Get-Verb are flagged, as are functions not named Verb-Noun. A comparison with $null on the right side is reported, because it filters arrays instead of testing them. Write-Host and Invoke-Expression are noted, unclosed brackets and strings are reported with their line, and a .psd1 manifest without a hashtable is flagged.
Worked example
The sample Backup-Logs.ps1 has 30 lines with no indentation at all. With the OTBS preset it becomes 29 lines: 15 changed, 5 added and 6 removed. The parameter list and the body of Archive-OldLogs are indented by four spaces, and the ForEach-Object line that continues the pipeline is indented four more. The hashtable becomes Name, RetentionDays and Compress with their = signs aligned under the longest key. If, Else, -LT, -EQ, get-date and write-output get canonical casing, and the call archive-oldlogs is matched to the declared name, seven corrections in all. Four warnings remain: the gci and ? aliases, the unapproved verb Archive, and "$result -eq $null". The here-string is copied unchanged.
Limits
The built-in formatter does not run PowerShell's own parser, so it cannot report every syntax error, and it does not reorder parameters or rewrite logic. Casing correction covers about 140 common cmdlets plus the functions in the file; other commands keep the casing you used. Allman mode moves braces only for keywords and function definitions, never for script blocks passed to cmdlets, because that would change what the script does.
Esempio svolto
Backup-Logs.ps1 with OTBS: 30 lines become 29, hashtable = aligned, 7 casing fixes, warnings for gci, ?, Archive and $null on the right.
In breve
- Categoria: Sviluppo e dati
- Funziona nel browser, senza registrazione né caricamento.
- Le informazioni che inserisci restano sul tuo dispositivo.
- Disponibile in inglese.
- Contenuto rivisto l'ultima volta il:
- Fonte ufficiale: PSScriptAnalyzer rules
Domande frequenti
Which brace styles are available?
OTBS keeps opening braces on the same line and writes } else {. Stroustrup puts else on a new line. Allman puts the braces of keywords and functions on their own line.
Will it break my commands by changing spaces?
No. Spaces are only changed around assignments, pipes, commas and braces, and after keywords. Arguments, paths, -Parameters and member access keep the spacing you wrote.
Can it replace aliases with full cmdlet names?
Yes. Turn on Expand aliases. Aliases are only replaced where a command is expected, such as at the start of a line or after a pipe, so a word like select inside text is left alone.
How does it know the right casing?
It has a list of common cmdlets with their official casing and also learns the functions you declare in the script, so calls to them match the declaration.
Does it support modules and manifests?
Yes. .ps1, .psm1 and .psd1 files are accepted, and a manifest is checked for its hashtable.
Does the script run?
No. The tool only reads the text. Nothing is executed, and nothing leaves your browser.
