| external help file | Microsoft.Windows.PowerShell.ScriptAnalyzer.dll-Help.xml |
|---|---|
| Module Name | PSScriptAnalyzer |
| ms.date | 10/07/2021 |
| online version | https://learn.microsoft.com/powershell/module/psscriptanalyzer/invoke-formatter?view=ps-modules&wt.mc_id=ps-gethelp |
| schema | 2.0.0 |
Formats a script text based on the input settings or default settings.
Invoke-Formatter [-ScriptDefinition] <string> [[-Settings] <Object>] [[-Range] <int[]>]
[<CommonParameters>]
The Invoke-Formatter cmdlet takes a string input and formats it according to defined settings. If
no Settings parameter is provided, the cmdlet assumes the default code formatting settings as
defined in Settings/CodeFormatting.psd1.
$scriptDefinition = @'
function foo {
"hello"
}
'@
Invoke-Formatter -ScriptDefinition $scriptDefinitionfunction foo {
"hello"
}
$scriptDefinition = @'
function foo {
"hello"
}
'@
$settings = @{
IncludeRules = @("PSPlaceOpenBrace", "PSUseConsistentIndentation")
Rules = @{
PSPlaceOpenBrace = @{
Enable = $true
OnSameLine = $false
}
PSUseConsistentIndentation = @{
Enable = $true
}
}
}
Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settingsfunction foo
{
"hello"
}
Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings /path/to/settings.psd1The range within which formatting should take place. The value of this parameter must be an array of four integers. These numbers must be greater than 0. The four integers represent the following four values in this order:
- starting line number
- starting column number
- ending line number
- ending column number
Type: Int32[]
Parameter Sets: (All)
Aliases:
Required: False
Position: 3
Default value: None
Accept pipeline input: True
Accept wildcard characters: FalseThe text of the script to be formatted represented as a string. This is not a ScriptBlock object.
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: FalseA settings hashtable or a path to a PowerShell data file (.psd1) that contains the settings.
Type: Object
Parameter Sets: (All)
Aliases:
Required: False
Position: 2
Default value: CodeFormatting
Accept pipeline input: True
Accept wildcard characters: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
The formatted string result.