├── .build.ps1 ├── .gitattributes ├── .gitignore ├── .vscode └── launch.json ├── Build.ps1 ├── FormatPowershellCode.psd1 ├── FormatPowershellCode.psm1 ├── Install.ps1 ├── LICENSE.md ├── README.md ├── build ├── .buildenvironment.ps1 └── dotSource │ ├── Convert-ArrayToString.ps1 │ ├── Convert-HashToString.ps1 │ ├── New-PSGalleryProjectProfile.ps1 │ ├── Out-Zip.ps1 │ ├── README.md │ ├── Remove-Signature.ps1 │ ├── Replace-FileString.ps1 │ ├── Update-PSGalleryProjectProfile.ps1 │ └── Upload-ProjectToPSGallery.ps1 ├── en-US └── about_FormatPowershellCode.help.txt ├── function-status-table.csv ├── release ├── 1.4.0 │ ├── FormatPowerShellCode.psm1 │ ├── FormatPowershellCode.psd1 │ ├── docs │ │ ├── Format-ScriptCondenseEnclosures.md │ │ ├── Format-ScriptExpandFunctionBlocks.md │ │ ├── Format-ScriptExpandNamedBlocks.md │ │ ├── Format-ScriptExpandParameterBlocks.md │ │ ├── Format-ScriptExpandStatementBlocks.md │ │ ├── Format-ScriptExpandTypeAccelerators.md │ │ ├── Format-ScriptFormatCodeIndentation.md │ │ ├── Format-ScriptFormatCommandNames.md │ │ ├── Format-ScriptFormatTypeNames.md │ │ ├── Format-ScriptPadExpressions.md │ │ ├── Format-ScriptPadOperators.md │ │ ├── Format-ScriptReduceLineLength.md │ │ ├── Format-ScriptRemoveStatementSeparators.md │ │ ├── Format-ScriptRemoveSuperfluousSpaces.md │ │ ├── Format-ScriptReplaceHereStrings.md │ │ ├── Format-ScriptReplaceInvalidCharacters.md │ │ ├── Format-ScriptTestCodeBlock.md │ │ └── FormatPowershellCode.md │ └── en-US │ │ ├── FormatPowerShellCode-help.xml │ │ ├── FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_HelpInfo.xml │ │ ├── FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_en-US_helpcontent.cab │ │ └── about_FormatPowershellCode.help.txt ├── 1.4.1 │ ├── FormatPowerShellCode.psm1 │ ├── FormatPowershellCode.psd1 │ ├── docs │ │ ├── Format-ScriptCondenseEnclosures.md │ │ ├── Format-ScriptExpandFunctionBlocks.md │ │ ├── Format-ScriptExpandNamedBlocks.md │ │ ├── Format-ScriptExpandParameterBlocks.md │ │ ├── Format-ScriptExpandStatementBlocks.md │ │ ├── Format-ScriptExpandTypeAccelerators.md │ │ ├── Format-ScriptFormatCodeIndentation.md │ │ ├── Format-ScriptFormatCommandNames.md │ │ ├── Format-ScriptFormatTypeNames.md │ │ ├── Format-ScriptPadExpressions.md │ │ ├── Format-ScriptPadOperators.md │ │ ├── Format-ScriptReduceLineLength.md │ │ ├── Format-ScriptRemoveStatementSeparators.md │ │ ├── Format-ScriptRemoveSuperfluousSpaces.md │ │ ├── Format-ScriptReplaceHereStrings.md │ │ ├── Format-ScriptReplaceInvalidCharacters.md │ │ ├── Format-ScriptTestCodeBlock.md │ │ └── FormatPowershellCode.md │ └── en-US │ │ ├── FormatPowerShellCode-help.xml │ │ ├── FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_HelpInfo.xml │ │ ├── FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_en-US_helpcontent.cab │ │ └── about_FormatPowershellCode.help.txt ├── FormatPowershellCode-1.4.0.zip ├── FormatPowershellCode-1.4.1.zip ├── FormatPowershellCode-current.zip └── FormatPowershellCode │ ├── FormatPowerShellCode.psm1 │ ├── FormatPowershellCode.psd1 │ ├── docs │ ├── Format-ScriptCondenseEnclosures.md │ ├── Format-ScriptExpandFunctionBlocks.md │ ├── Format-ScriptExpandNamedBlocks.md │ ├── Format-ScriptExpandParameterBlocks.md │ ├── Format-ScriptExpandStatementBlocks.md │ ├── Format-ScriptExpandTypeAccelerators.md │ ├── Format-ScriptFormatCodeIndentation.md │ ├── Format-ScriptFormatCommandNames.md │ ├── Format-ScriptFormatTypeNames.md │ ├── Format-ScriptPadExpressions.md │ ├── Format-ScriptPadOperators.md │ ├── Format-ScriptReduceLineLength.md │ ├── Format-ScriptRemoveStatementSeparators.md │ ├── Format-ScriptRemoveSuperfluousSpaces.md │ ├── Format-ScriptReplaceHereStrings.md │ ├── Format-ScriptReplaceInvalidCharacters.md │ ├── Format-ScriptTestCodeBlock.md │ └── FormatPowershellCode.md │ └── en-US │ ├── FormatPowerShellCode-help.xml │ ├── FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_HelpInfo.xml │ ├── FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_en-US_helpcontent.cab │ └── about_FormatPowershellCode.help.txt ├── src ├── depreciated │ ├── Format-ScriptConvertKeywordsAndOperatorsToLower.ps1 │ ├── Format-ScriptExpandAliases.ps1 │ └── Format-ScriptRemoveStatementSeparatorsOld.ps1 ├── other │ └── 1_globals.ps1 ├── private │ ├── Format-ScriptGetKindLines.ps1 │ ├── Format-ScriptGetKindLocations.ps1 │ ├── FormatScript-Definitions.ps1 │ ├── Get-BreakableTokens.ps1 │ ├── Get-CallerPreference.ps1 │ ├── Get-NewToken.ps1 │ ├── Get-ParentASTTypes.ps1 │ ├── Get-TokenKindLocations.ps1 │ ├── Get-TokensBetweenLines.ps1 │ ├── Get-TokensOnLineNumber.ps1 │ └── Update-EscapableCharacters.ps1 ├── public │ ├── Format-ScriptCondenseEnclosures.ps1 │ ├── Format-ScriptExpandFunctionBlocks.ps1 │ ├── Format-ScriptExpandNamedBlocks.ps1 │ ├── Format-ScriptExpandParameterBlocks.ps1 │ ├── Format-ScriptExpandStatementBlocks.ps1 │ ├── Format-ScriptExpandTypeAccelerators.ps1 │ ├── Format-ScriptFormatCodeIndentation.ps1 │ ├── Format-ScriptFormatCommandNames.ps1 │ ├── Format-ScriptFormatTypeNames.ps1 │ ├── Format-ScriptPadExpressions.ps1 │ ├── Format-ScriptPadOperators.ps1 │ ├── Format-ScriptReduceLineLength.ps1 │ ├── Format-ScriptRemoveStatementSeparators.ps1 │ ├── Format-ScriptRemoveSuperfluousSpaces.ps1 │ ├── Format-ScriptReplaceHereStrings.ps1 │ ├── Format-ScriptReplaceInvalidCharacters.ps1 │ └── Format-ScriptTestCodeBlock.ps1 └── working │ ├── Expand-Aliases.ps1 │ ├── Format-ScriptReplaceTabCharacters.ps1 │ ├── Format-ScriptTemplateFunction.ps1 │ └── Get-FunctionParameters.ps1 ├── test └── Pester │ └── Data │ ├── example-transform1.ps1 │ ├── newtest.ps1 │ ├── testcase-assignmentop.ps1 │ ├── testcase-codeblockexpansion.ps1 │ ├── testcase-condenseenclosures.ps1 │ ├── testcase-lotsofvariables.ps1 │ ├── testcase-lotsofvariables2.ps1 │ ├── testcase-multipleembeddedparamblocks.ps1 │ ├── testcase-strings.ps1 │ └── testcase-verylargefunction.ps1 └── version.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore any temp directory (used in build steps) 2 | temp/ 3 | 4 | # PSGallery publishing file can contain personal API key and paths and thus we want to ignore it if it exists 5 | .psgallery 6 | 7 | # Just in case I'm a few screws loose and leave a copy of this in any project directory, ignore it. 8 | psgalleryapi.txt 9 | 10 | # Others you probably don't want or need to be public 11 | ~$* 12 | *~ 13 | *.pfx 14 | 15 | ############# 16 | ## Windows detritus 17 | ############# 18 | 19 | # Windows image file caches 20 | Thumbs.db 21 | ehthumbs.db 22 | 23 | # Folder config file 24 | Desktop.ini 25 | 26 | # Recycle Bin used on file shares 27 | $RECYCLE.BIN/ 28 | 29 | # Mac crap 30 | .DS_Store -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "PowerShell", 6 | "type": "PowerShell", 7 | "request": "launch", 8 | "program": "${file}", 9 | "args": [], 10 | "cwd": "${file}" 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /Build.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Version 5 2 | 3 | <# 4 | .Synopsis 5 | Build script using Invoke-Build (https://github.com/nightroman/Invoke-Build) 6 | .Description 7 | The script automates the build process for the FormatPowerShellCode module. 8 | 9 | The overarching build steps are: 10 | * Clean up the build temp directory 11 | * In the temp directory: 12 | - Create project folder structure 13 | - Copy over project files 14 | - Format PowerShell files with the FormatPowerShellCode module 15 | - Create module markdown files (PlatyPS) 16 | - Convert markdown files to HTML documents for online help (PlatyPS) 17 | - Create and automatically fill in the blanks for the online help landing page (PlatyPS) 18 | - Create the online help cab download (PlatyPS) 19 | - Update module manifest with exported functions and new version. 20 | - Combine the existing public and private PowerShell script files into one psm1 21 | 22 | Some additional or planned build steps are: 23 | * Automatically kick of Pester testing 24 | * Push the release with a tag to GitHub 25 | * Push the release to PSGallery 26 | 27 | This build script has several dependencies which are delt with in the 'Configure' task 28 | Invoke-Build - Runs build tasks 29 | PlatyPS - Create html help files 30 | FormatPowerShellCode - Pretty up the code (This build script is for this same module so not really a dependency but still...) 31 | .psgallery - File containing information for pushing module to psgallery 32 | version.txt - Used to determine version of build to create (all versions will overwrite the 'current' release folder) 33 | 34 | To run the basic build: 35 | .\build.ps1 36 | 37 | To update your project version number (basically update your module manifest automatically) first update the version.txt file then run: 38 | Import-Module InvokeBuild 39 | Invoke-Build UpdateVersion 40 | 41 | To publish to the PSGallery site (assuming you have a filled out galleryapi.txt file in your profile path) 42 | Import-Module InvokeBuild 43 | Invoke-Build PublishPSGallery -ReleaseNotes 'First real release' 44 | 45 | Notes: 46 | - The manifest file is assumed to already exist but it doesn't matter if it is exporting every function. When it is recreated only 'public' functions will be defined. 47 | - This build is based on your existing module being loaded as it is and will infer information from it to build the final release module. 48 | - The release number is driven by the version.txt file in the root of your module project directory. You can update the exising module 49 | manifest in this directory with this version with some additional invoke-build tasks. 50 | - I use powershellget to ease installation of required modules. This will have to be rewritten in several spots to attain any kind of 51 | backward compatibility from PowerShell 5.0 52 | - There is no real accounting for exported variables, aliases, or other public content in this script. The manifest will copy over manually defined 53 | items in the manifest though.. 54 | 55 | #> 56 | if ((get-module InvokeBuild -ListAvailable) -eq $null) { 57 | Write-Host -NoNewLine " Installing InvokeBuild module" 58 | $null = Install-Module InvokeBuild 59 | Write-Host -ForegroundColor Green '...Installed!' 60 | } 61 | if (get-module InvokeBuild -ListAvailable) { 62 | Write-Host -NoNewLine " Importing InvokeBuild module" 63 | Import-Module InvokeBuild -Force 64 | Write-Host -ForegroundColor Green '...Loaded!' 65 | } 66 | else { 67 | throw 'How did you even get here?' 68 | } 69 | 70 | # Kick off the standard build 71 | try { 72 | Invoke-Build 73 | } 74 | catch { 75 | # If it fails then show the error and try to clean up the environment 76 | Write-Host -ForegroundColor Red 'Build Failed with the following error:' 77 | Write-Output $_ 78 | } 79 | finally { 80 | Write-Host '' 81 | Write-Host 'Attempting to clean up the session (loaded modules and such)...' 82 | Invoke-Build BuildSessionCleanup 83 | Remove-Module InvokeBuild 84 | } -------------------------------------------------------------------------------- /FormatPowershellCode.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'FormatPowerShellCode' 3 | # 4 | # Generated by: Zachary Loeber 5 | # 6 | # Generated on: 10/15/2015 7 | # 8 | 9 | @{ 10 | 11 | # Script module or binary module file associated with this manifest. 12 | RootModule = 'FormatPowerShellCode.psm1' 13 | 14 | # Version number of this module. 15 | ModuleVersion = '1.4.1' 16 | 17 | # ID used to uniquely identify this module 18 | GUID = 'dcfbce3c-18be-4775-b98d-4431d4fb9e08' 19 | 20 | # Author of this module 21 | Author = 'Zachary Loeber' 22 | 23 | # Company or vendor of this module 24 | CompanyName = 'None' 25 | 26 | # Copyright statement for this module 27 | Copyright = '(c) 2016 Zachary Loeber. All rights reserved.' 28 | 29 | # Description of the functionality provided by this module 30 | Description = 'A set of functions for standardizing and reformatting PowerShell script code.' 31 | 32 | # Minimum version of the Windows PowerShell engine required by this module 33 | PowerShellVersion = '3.0' 34 | 35 | # Name of the Windows PowerShell host required by this module 36 | # PowerShellHostName = '' 37 | 38 | # Minimum version of the Windows PowerShell host required by this module 39 | # PowerShellHostVersion = '' 40 | 41 | # Minimum version of Microsoft .NET Framework required by this module 42 | # DotNetFrameworkVersion = '' 43 | 44 | # Minimum version of the common language runtime (CLR) required by this module 45 | # CLRVersion = '' 46 | 47 | # Processor architecture (None, X86, Amd64) required by this module 48 | # ProcessorArchitecture = '' 49 | 50 | # Modules that must be imported into the global environment prior to importing this module 51 | # RequiredModules = @() 52 | 53 | # Assemblies that must be loaded prior to importing this module 54 | # RequiredAssemblies = @() 55 | 56 | # Script files (.ps1) that are run in the caller's environment prior to importing this module. 57 | # ScriptsToProcess = @() 58 | 59 | # Type files (.ps1xml) to be loaded when importing this module 60 | # TypesToProcess = @() 61 | 62 | # Format files (.ps1xml) to be loaded when importing this module 63 | #FormatsToProcess = '' 64 | 65 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 66 | # NestedModules = @() 67 | 68 | # Functions to export from this module 69 | FunctionsToExport = '*' 70 | 71 | # Cmdlets to export from this module 72 | CmdletsToExport = '' 73 | 74 | # Variables to export from this module 75 | VariablesToExport = '' 76 | 77 | # Aliases to export from this module 78 | AliasesToExport = '' 79 | 80 | # DSC resources to export from this module 81 | # DscResourcesToExport = @() 82 | 83 | # List of all modules packaged with this module 84 | # ModuleList = @() 85 | 86 | # List of all files packaged with this module 87 | # FileList = @() 88 | 89 | # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. 90 | PrivateData = @{ 91 | 92 | PSData = @{ 93 | Category = 'Code Formatting' 94 | 95 | # Tags applied to this module. These help with module discovery in online galleries. 96 | Tags = @('powershell', 'syntax', 'AST', 'beautifier') 97 | 98 | # A URL to the license for this module. 99 | LicenseUri = 'https://github.com/zloeber/FormatPowershellCode/blob/master/LICENSE.md' 100 | 101 | # A URL to the main website for this project. 102 | ProjectUri = 'https://github.com/zloeber/FormatPowershellCode' 103 | 104 | # A URL to an icon representing this module. 105 | # IconUri = '' 106 | 107 | # ReleaseNotes of this module 108 | # ReleaseNotes = '' 109 | 110 | } # End of PSData hashtable 111 | 112 | } # End of PrivateData hashtable 113 | 114 | # HelpInfo URI of this module 115 | # HelpInfoURI = '' 116 | 117 | # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. 118 | # DefaultCommandPrefix = '' 119 | 120 | } -------------------------------------------------------------------------------- /FormatPowershellCode.psm1: -------------------------------------------------------------------------------- 1 | # This psm1 file is purely for development. The build script will recreate this file entirely. 2 | 3 | # Private and other methods and variables 4 | Get-ChildItem '.\src\private','.\src\other' -Recurse -Filter "*.ps1" -File | Sort-Object Name | Foreach { 5 | Write-Verbose "Dot sourcing private script file: $($_.Name)" 6 | . $_.FullName 7 | } 8 | 9 | # Load and export public methods 10 | Get-ChildItem '.\src\public' -Recurse -Filter "*.ps1" -File | Sort-Object Name | Foreach { 11 | Write-Verbose "Dot sourcing public script file: $($_.Name)" 12 | . $_.FullName 13 | 14 | # Find all the functions defined no deeper than the first level deep and export it. 15 | # This looks ugly but allows us to not keep any uneeded variables in memory that are not related to the module. 16 | ([System.Management.Automation.Language.Parser]::ParseInput((Get-Content -Path $_.FullName -Raw), [ref]$null, [ref]$null)).FindAll({ $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $false) | Foreach { 17 | Export-ModuleMember $_.Name 18 | } 19 | } -------------------------------------------------------------------------------- /Install.ps1: -------------------------------------------------------------------------------- 1 | # Run this in an administrative PowerShell prompt to install the FormatPowershellCode PowerShell module: 2 | # 3 | # iex (New-Object Net.WebClient).DownloadString("https://github.com/zloeber/FormatPowershellCode/raw/master/Install.ps1") 4 | 5 | # Some general variables 6 | $ModuleName = 'FormatPowershellCode' 7 | $DownloadURL = 'https://github.com/zloeber/FormatPowershellCode/raw/master/release/FormatPowershellCode-current.zip' 8 | 9 | # Download and install the module 10 | $webclient = New-Object System.Net.WebClient 11 | $file = "$($env:TEMP)\$($ModuleName).zip" 12 | 13 | Write-Host "Downloading latest version of $ModuleName from $DownloadURL" -ForegroundColor Cyan 14 | $webclient.DownloadFile($DownloadURL,$file) 15 | Write-Host "File saved to $file" -ForegroundColor Green 16 | $targetondisk = "$($env:USERPROFILE)\Documents\WindowsPowerShell\Modules\$($ModuleName)" 17 | $null = New-Item -ItemType Directory -Force -Path $targetondisk 18 | $shell_app=new-object -com shell.application 19 | $zip_file = $shell_app.namespace($file) 20 | Write-Host "Uncompressing the Zip file to $($targetondisk)" -ForegroundColor Cyan 21 | $destination = $shell_app.namespace($targetondisk) 22 | $destination.Copyhere($zip_file.items(), 0x10) 23 | 24 | Write-Host "Module has been installed!" -ForegroundColor Green 25 | Write-Host "You can now import the module with: Import-Module -Name $ModuleName" -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 |

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License, please attribute to Zachary Loeber and the PowerShell Community.

2 | 3 |
You are free to:
4 | 5 |

Share — copy and redistribute the material in any medium or format

6 | 7 |

Adapt — remix, transform, and build upon the material

8 | 9 |

The authors encourage you to redistribute this content as widely as possible, but require that you give credit to the primary authors below, and that you notify us on github of any improvements you make.

-------------------------------------------------------------------------------- /build/.buildenvironment.ps1: -------------------------------------------------------------------------------- 1 | # Update these to suit your PowerShell module build. These variables get dot sourced into 2 | # the build at every run. The path root of the locations are assumed to be at the root of the 3 | # PowerShell module project directory. 4 | 5 | # The module we are building 6 | $ModuleToBuild = 'FormatPowershellCode' 7 | 8 | # Project website (used for external help cab file definition) 9 | $ModuleWebsite = 'https://github.com/zloeber/FormatPowershellCode' 10 | 11 | # Public functions (to be exported by file name as the function name) 12 | $PublicFunctionSource = 'src\public' 13 | 14 | # Private function source 15 | $PrivateFunctionSource = 'src\private' 16 | 17 | # Other module source 18 | $OtherModuleSource = 'src\other' 19 | 20 | # Release directory. You typically want a module to reside in a folder of the same name in order to publish to psgallery 21 | # among other things. 22 | $BaseReleaseFolder = 'release' 23 | 24 | # Build tool path (these scripts are dot sourced) 25 | $BuildToolFolder = 'build' 26 | 27 | # Scratch path - this is where all our scratch work occurs. It will be cleared out at every run. 28 | $ScratchFolder = 'temp' -------------------------------------------------------------------------------- /build/dotSource/Convert-ArrayToString.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Converts array to a Powershell string representing the array as a codeblock. 4 | .DESCRIPTION 5 | Converts array to a Powershell string representing the array as a codeblock. 6 | .PARAMETER Array 7 | Array to convert. 8 | .PARAMETER Flatten 9 | No newlines in output. 10 | .EXAMPLE 11 | $test = @('a','b','c') 12 | Convert-ArrayToString $test 13 | 14 | Description 15 | ----------- 16 | Outputs the following to the screen: 17 | @( 18 | 'a', 19 | 'b', 20 | 'c' 21 | ) 22 | 23 | .NOTES 24 | None 25 | .LINK 26 | None 27 | .LINK 28 | None 29 | #> 30 | function Script:Convert-ArrayToString 31 | { 32 | [cmdletbinding()] 33 | 34 | Param 35 | ( 36 | [Parameter(Mandatory=$true,Position=0)] 37 | [AllowEmptyCollection()] 38 | [Array]$Array, 39 | 40 | [Parameter(Mandatory=$False)] 41 | [switch]$Flatten 42 | ) 43 | 44 | Begin{ 45 | If($Flatten) 46 | { 47 | $Mode = 'Append' 48 | } 49 | Else 50 | { 51 | $Mode = 'AppendLine' 52 | } 53 | 54 | If($Flatten -or $Array.Count -eq 0) 55 | { 56 | $Indenting = '' 57 | $RecursiveIndenting = '' 58 | } 59 | Else{ 60 | $Indenting = ' ' 61 | $RecursiveIndenting = ' ' * (Get-PSCallStack).Where({$_.Command -match 'Convert-ArrayToString|Convert-HashToSTring' -and $_.InvocationInfo.CommandOrigin -eq 'Internal' -and $_.InvocationInfo.Line -notmatch '\$This'}).Count 62 | } 63 | } 64 | 65 | Process{ 66 | $StringBuilder = [System.Text.StringBuilder]::new() 67 | 68 | If($Array.Count -ge 1) 69 | { 70 | [void]$StringBuilder.$Mode("@(") 71 | } 72 | Else 73 | { 74 | [void]$StringBuilder.Append("@(") 75 | } 76 | 77 | For($i = 0; $i -lt $Array.Count; $i++) 78 | { 79 | $Item = $Array[$i] 80 | 81 | If($Item -is [String]) 82 | { 83 | [void]$StringBuilder.Append($Indenting + $RecursiveIndenting + "'$Item'") 84 | } 85 | ElseIf($Item -is [int] -or $Value -is [double]) 86 | { 87 | [void]$StringBuilder.Append($Indenting + $RecursiveIndenting + "$($Item.ToString())") 88 | } 89 | ElseIf($Item -is [bool]) 90 | { 91 | [void]$StringBuilder.Append($Indenting + $RecursiveIndenting + "`$$Item") 92 | } 93 | ElseIf($Item -is [array]) 94 | { 95 | $Value = Convert-ArrayToString -Array $Item -Flatten:$Flatten 96 | 97 | [void]$StringBuilder.Append($Indenting + $RecursiveIndenting + $Value) 98 | } 99 | ElseIf($Item -is [hashtable]) 100 | { 101 | $Value = Convert-HashToSTring -Hashtable $Item -Flatten:$Flatten 102 | 103 | [void]$StringBuilder.Append($Indenting + $RecursiveIndenting + $Value) 104 | } 105 | Else 106 | { 107 | Throw "Array element is not of known type." 108 | } 109 | 110 | If($i -lt ($Array.Count - 1)) 111 | { 112 | [void]$StringBuilder.$Mode(', ') 113 | } 114 | ElseIf(-not $Flatten) 115 | { 116 | [void]$StringBuilder.AppendLine('') 117 | } 118 | } 119 | 120 | [void]$StringBuilder.Append($RecursiveIndenting + ')') 121 | 122 | $StringBuilder.ToString() 123 | } 124 | 125 | End{} 126 | } -------------------------------------------------------------------------------- /build/dotSource/Convert-HashToString.ps1: -------------------------------------------------------------------------------- 1 | function Script:Convert-HashToString 2 | { 3 | [cmdletbinding()] 4 | 5 | Param ( 6 | [Parameter(Mandatory=$true,Position=0)] 7 | [Hashtable]$Hashtable, 8 | 9 | [Parameter(Mandatory=$False)] 10 | [switch]$Flatten 11 | ) 12 | 13 | Begin{ 14 | If($Flatten -or $Hashtable.Keys.Count -eq 0) 15 | { 16 | $Mode = 'Append' 17 | $Indenting = '' 18 | $RecursiveIndenting = '' 19 | } 20 | Else{ 21 | $Mode = 'Appendline' 22 | $Indenting = ' ' 23 | $RecursiveIndenting = ' ' * (Get-PSCallStack).Where({$_.Command -match 'Convert-ArrayToString|Convert-HashToSTring' -and $_.InvocationInfo.CommandOrigin -eq 'Internal' -and $_.InvocationInfo.Line -notmatch '\$This'}).Count 24 | } 25 | } 26 | 27 | Process{ 28 | $StringBuilder = [System.Text.StringBuilder]::new() 29 | 30 | If($Hashtable.Keys.Count -ge 1) 31 | { 32 | [void]$StringBuilder.$Mode("@{") 33 | } 34 | Else 35 | { 36 | [void]$StringBuilder.Append("@{") 37 | } 38 | 39 | Foreach($Key in $Hashtable.Keys) 40 | { 41 | $Value = $Hashtable[$Key] 42 | 43 | If($Key -match '\s') 44 | { 45 | $Key = "'$Key'" 46 | } 47 | 48 | If($Value -is [String]) 49 | { 50 | [void]$StringBuilder.$Mode($Indenting + $RecursiveIndenting + "$Key = '$Value'") 51 | } 52 | ElseIf($Value -is [int] -or $Value -is [double]) 53 | { 54 | [void]$StringBuilder.$Mode($Indenting + $RecursiveIndenting + "$Key = $($Value.ToString())") 55 | } 56 | ElseIf($Value -is [bool]) 57 | { 58 | [void]$StringBuilder.$Mode($Indenting + $RecursiveIndenting + "$Key = `$$Value") 59 | } 60 | ElseIf($Value -is [array]) 61 | { 62 | $Value = Convert-ArrayToString -Array $Value -Flatten:$Flatten 63 | 64 | [void]$StringBuilder.$Mode($Indenting + $RecursiveIndenting + "$Key = $Value") 65 | } 66 | ElseIf($Value -is [hashtable]) 67 | { 68 | $Value = Convert-HashToSTring -Hashtable $Value -Flatten:$Flatten 69 | [void]$StringBuilder.$Mode($Indenting + $RecursiveIndenting + "$Key = $Value") 70 | } 71 | Else 72 | { 73 | Throw "Key value is not of known type." 74 | } 75 | 76 | If($Flatten){[void]$StringBuilder.Append("; ")} 77 | } 78 | 79 | [void]$StringBuilder.Append($RecursiveIndenting + "}") 80 | 81 | $StringBuilder.ToString().Replace("; }",'}') 82 | } 83 | 84 | End{} 85 | } 86 | 87 | #Remove-TypeData -TypeName System.Collections.HashTable -ErrorAction SilentlyContinue 88 | #Update-TypeData -TypeName System.Collections.HashTable -MemberType ScriptMethod -MemberName ToString -Value {Convert-HashToString $This} -------------------------------------------------------------------------------- /build/dotSource/New-PSGalleryProjectProfile.ps1: -------------------------------------------------------------------------------- 1 | #Requires -version 5 2 | function Script:New-PSGalleryProjectProfile { 3 | <# 4 | .SYNOPSIS 5 | Create a powershell Gallery module upload profile 6 | .DESCRIPTION 7 | Create a powershell Gallery module upload profile. Some items (like Name) are inferred from the module manifest and are left out. 8 | .PARAMETER Path 9 | Path of module project files to upload. 10 | .PARAMETER ProjectUri 11 | Module project website. 12 | .PARAMETER Tags 13 | Tags used to search for the module (separated by commas) 14 | .PARAMETER Repository 15 | Destination gallery (default is PSGallery) 16 | .PARAMETER ReleaseNotes 17 | Release notes. 18 | .PARAMETER LicenseUri 19 | License website. 20 | .PARAMETER IconUri 21 | Icon web path. 22 | .PARAMETER NuGetApiKey 23 | API key for the powershellgallery.com site. 24 | .PARAMETER OutputFile 25 | OutputFile (default is .psgallery) 26 | 27 | .EXAMPLE 28 | .NOTES 29 | Author: Zachary Loeber 30 | Site: http://www.the-little-things.net/ 31 | Version History 32 | 1.0.0 - Initial release 33 | #> 34 | [CmdletBinding()] 35 | param( 36 | [parameter(Position=0, Mandatory=$true, HelpMessage='Path of module project files to upload.')] 37 | [string]$Path, 38 | [parameter(Position=1, HelpMessage='Module project website.')] 39 | [string]$ProjectUri = '', 40 | [parameter(Position=2, HelpMessage='Tags used to search for the module (separated by commas)')] 41 | [string]$Tags = '', 42 | [parameter(Position=3, HelpMessage='Destination gallery (default is PSGallery)')] 43 | [string]$Repository = 'PSGallery', 44 | [parameter(Position=4, HelpMessage='Release notes.')] 45 | [string]$ReleaseNotes = '', 46 | [parameter(Position=5, HelpMessage=' License website.')] 47 | [string]$LicenseUri = '', 48 | [parameter(Position=6, HelpMessage='Icon web path.')] 49 | [string]$IconUri = '', 50 | [parameter(Position=7, HelpMessage='NugetAPI key for the powershellgallery.com site.')] 51 | [string]$NuGetApiKey = '', 52 | [parameter(Position=8, HelpMessage='OutputFile (default is .psgallery)')] 53 | [string]$OutputFile = '.psgallery' 54 | ) 55 | 56 | $PublishParams = @{ 57 | Path = $Path 58 | NuGetApiKey = $NuGetApiKey 59 | ProjectUri = $ProjectUri 60 | Tags = $Tags 61 | Repository = $Repository 62 | ReleaseNotes = $ReleaseNotes 63 | LicenseUri = $LicenseUri 64 | IconUri = $IconUri 65 | } 66 | 67 | if (Test-Path $OutputFile) { 68 | $PublishParams | Export-Clixml -Path $OutputFile -confirm 69 | } 70 | else { 71 | $PublishParams | Export-Clixml -Path $OutputFile 72 | } 73 | } -------------------------------------------------------------------------------- /build/dotSource/Out-Zip.ps1: -------------------------------------------------------------------------------- 1 | function Script:Out-Zip { 2 | param ( 3 | [Parameter(Position=0, Mandatory=$true)] 4 | [string] $Directory, 5 | [Parameter(Position=1, Mandatory=$true)] 6 | [string] $FileName, 7 | [Parameter(Position=2)] 8 | [switch] $overwrite 9 | ) 10 | Add-Type -Assembly System.IO.Compression.FileSystem 11 | $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal 12 | if (-not $FileName.EndsWith('.zip')) {$FileName += '.zip'} 13 | if ($overwrite) { 14 | if (Test-Path $FileName) { 15 | Remove-Item $FileName 16 | } 17 | } 18 | [System.IO.Compression.ZipFile]::CreateFromDirectory($Directory, $FileName, $compressionLevel, $false) 19 | } -------------------------------------------------------------------------------- /build/dotSource/README.md: -------------------------------------------------------------------------------- 1 | # Note 2 | These are extra functions used in the build script. They are purposefully scoped to the script level so as to be useable outside of the task level they are dot sourced within (the global scope would leave them in the session after build script is called so we cannot use that). -------------------------------------------------------------------------------- /build/dotSource/Remove-Signature.ps1: -------------------------------------------------------------------------------- 1 | #requires -Version 2 2 | function Script:Remove-Signature 3 | { 4 | [cmdletbinding()] 5 | 6 | Param( 7 | [Parameter(Mandatory = $False,Position = 0,ValueFromPipeline = $True,ValueFromPipelineByPropertyName = $True)] 8 | [Alias('Path')] 9 | [system.io.fileinfo[]]$FilePath 10 | ) 11 | 12 | Begin{ 13 | Push-Location -Path $env:USERPROFILE 14 | } 15 | 16 | Process{ 17 | $FilePath | 18 | ForEach-Object -Process { 19 | $Item = $_ 20 | 21 | If($Item.Extension -match '\.ps1|\.psm1|\.psd1|\.ps1xml') 22 | { 23 | Try 24 | { 25 | $Content = Get-Content -Path $Item.FullName -ErrorAction Stop 26 | 27 | $StringBuilder = New-Object -TypeName System.Text.StringBuilder -ErrorAction Stop 28 | 29 | Foreach($Line in $Content) 30 | { 31 | If($Line -match '^# SIG # Begin signature block|^') 32 | { 33 | Break 34 | } 35 | Else 36 | { 37 | $null = $StringBuilder.AppendLine($Line) 38 | } 39 | } 40 | 41 | Set-Content -Path $Item.FullName -Value $StringBuilder.ToString() 42 | } 43 | Catch 44 | { 45 | Write-Error -Message $_.Exception.Message 46 | } 47 | } 48 | } 49 | } 50 | 51 | End{ 52 | Pop-Location 53 | } 54 | } -------------------------------------------------------------------------------- /build/dotSource/Update-PSGalleryProjectProfile.ps1: -------------------------------------------------------------------------------- 1 | #Requires -version 5 2 | function Script:Update-PSGalleryProjectProfile { 3 | <# 4 | .SYNOPSIS 5 | Update a powershell Gallery module upload profile 6 | .DESCRIPTION 7 | Update a powershell Gallery module upload profile 8 | .PARAMETER Name 9 | Module short name. 10 | .PARAMETER Path 11 | Path of module project files to upload. 12 | .PARAMETER ProjectUri 13 | Module project website. 14 | .PARAMETER Tags 15 | Tags used to search for the module (separated by spaces) 16 | .PARAMETER RequiredVersion 17 | Module version 18 | .PARAMETER Repository 19 | Destination gallery (default is PSGallery) 20 | .PARAMETER ReleaseNotes 21 | Release notes. 22 | .PARAMETER LicenseUri 23 | License website. 24 | .PARAMETER IconUri 25 | Icon web path. 26 | .PARAMETER APIKey 27 | API key for the powershellgallery.com site. 28 | .PARAMETER OutputFile 29 | Input module configuration file (default is .psgallery) 30 | 31 | .EXAMPLE 32 | .NOTES 33 | Author: Zachary Loeber 34 | Site: http://www.the-little-things.net/ 35 | Version History 36 | 1.0.0 - Initial release 37 | #> 38 | [CmdletBinding()] 39 | param( 40 | [parameter(Position=0, HelpMessage='Module short name.')] 41 | [string]$Name, 42 | [parameter(Position=1, HelpMessage='Path of module project files to upload.')] 43 | [string]$Path, 44 | [parameter(Position=2, HelpMessage='Module project website.')] 45 | [string]$ProjectUri, 46 | [parameter(Position=3, HelpMessage='Tags used to search for the module (separated by spaces)')] 47 | [string]$Tags, 48 | [parameter(Position=4, HelpMessage='Required powershell version (default is 2)')] 49 | [string]$RequiredVersion, 50 | [parameter(Position=5, HelpMessage='Destination gallery (default is PSGallery)')] 51 | [string]$Repository, 52 | [parameter(Position=6, HelpMessage='Release notes.')] 53 | [string]$ReleaseNotes, 54 | [parameter(Position=7, HelpMessage='License website.')] 55 | [string]$LicenseUri, 56 | [parameter(Position=9, HelpMessage='Icon web path.')] 57 | [string]$IconUri, 58 | [parameter(Position=10, HelpMessage='API key for the powershellgallery.com site.')] 59 | [string]$NuGetApiKey, 60 | [parameter(Position=11, HelpMessage='Input module configuration file (default is .psgallery)')] 61 | [string]$InputFile = '.psgallery' 62 | ) 63 | 64 | if (Test-Path $InputFile) { 65 | $PublishParams = Import-Clixml $InputFile 66 | $MyParams = $PSCmdlet.MyInvocation.BoundParameters 67 | $MyParams.Keys | Where {$_ -ne 'InputFile'} | ForEach { 68 | Write-Verbose "Updating $($_)" 69 | if ($PublishParams.$_ -ne $null) { 70 | $PublishParams.$_ = $MyParams[$_] 71 | } 72 | } 73 | $PublishParams | Export-Clixml -Path $InputFile -Force 74 | } 75 | else { 76 | Write-Warning "InputFile was not found: $($InputFile)" 77 | } 78 | } -------------------------------------------------------------------------------- /en-US/about_FormatPowershellCode.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_FormatPowerShellCode 3 | 4 | SHORT DESCRIPTION 5 | A set of functions for standardizing and reformatting PowerShell script code. 6 | 7 | LONG DESCRIPTION 8 | A set of functions for standardizing and reformatting PowerShell script code. 9 | 10 | EXAMPLES 11 | import-module .\FormatPowershellCode.psm1 12 | get-content .\tests\testcase-codeblockexpansion.ps1 -raw | 13 | Format-ScriptRemoveStatementSeparators | 14 | Format-ScriptExpandFunctionBlocks | 15 | Format-ScriptExpandNamedBlocks | 16 | Format-ScriptExpandParameterBlocks | 17 | Format-ScriptExpandStatementBlocks | 18 | Format-ScriptFormatCodeIndentation | 19 | clip 20 | 21 | KEYWORDS 22 | Code Formatter, PowerShell Style 23 | 24 | SEE ALSO 25 | NA -------------------------------------------------------------------------------- /function-status-table.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zloeber/FormatPowershellCode/a8b1d2edec3ed074fa464d4f881556c6dc9e784e/function-status-table.csv -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptCondenseEnclosures.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptCondenseEnclosures 8 | ## SYNOPSIS 9 | Moves specified beginning enclosure types to the end of the prior line if found to be on its own line. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptCondenseEnclosures [-Code] [[-EnclosureStart] ] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Moves specified beginning enclosure types to the end of the prior line if found to be on its own line. 20 | 21 | ## EXAMPLES 22 | 23 | ### -------------------------- EXAMPLE 1 -------------------------- 24 | ``` 25 | $test = Get-Content -Raw -Path 'C:\testcases\test-pad-operators.ps1' 26 | ``` 27 | 28 | $test | Format-ScriptCondenseEnclosures | clip 29 | 30 | Description 31 | ----------- 32 | Moves all beginning enclosure characters to the prior line if found to be sitting at the beginning of a line. 33 | 34 | ## PARAMETERS 35 | 36 | ### -Code 37 | Multiple lines of code to analyze 38 | 39 | ```yaml 40 | Type: String[] 41 | Parameter Sets: (All) 42 | Aliases: 43 | 44 | Required: True 45 | Position: 1 46 | Default value: 47 | Accept pipeline input: True (ByValue) 48 | Accept wildcard characters: False 49 | ``` 50 | 51 | ### -EnclosureStart 52 | Array of starting enclosure characters to process (default is (, {, @(, and @{) 53 | 54 | ```yaml 55 | Type: String[] 56 | Parameter Sets: (All) 57 | Aliases: 58 | 59 | Required: False 60 | Position: 2 61 | Default value: @('{','(','@{','@(') 62 | Accept pipeline input: False 63 | Accept wildcard characters: False 64 | ``` 65 | 66 | ### -SkipPostProcessingValidityCheck 67 | After modifications have been made a check will be performed that the code has no errors. 68 | Use this switch to bypass this check (This is not recommended!) 69 | 70 | ```yaml 71 | Type: SwitchParameter 72 | Parameter Sets: (All) 73 | Aliases: 74 | 75 | Required: False 76 | Position: 3 77 | Default value: False 78 | Accept pipeline input: False 79 | Accept wildcard characters: False 80 | ``` 81 | 82 | ## INPUTS 83 | 84 | ## OUTPUTS 85 | 86 | ## NOTES 87 | This function fails to 'condense' anything really complex and probably shouldn't even be used... 88 | 89 | Author: Zachary Loeber 90 | Site: http://www.the-little-things.net/ 91 | 92 | 1.0.0 - 01/25/2015 93 | - Initial release 94 | 95 | ## RELATED LINKS 96 | 97 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 98 | 99 | [http://www.the-little-things.net](http://www.the-little-things.net) 100 | 101 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptExpandFunctionBlocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandFunctionBlocks 8 | ## SYNOPSIS 9 | Expand any function code blocks found in curly braces from inline to a more readable format. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandFunctionBlocks [-Code] [-DontExpandSingleLineBlocks] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Expand any function code blocks found in curly braces from inline to a more readable format. 20 | So this: 21 | function testfunction { Write-Output $_ } 22 | 23 | becomes this: 24 | function testfunction 25 | { 26 | Write-Output $_ 27 | } 28 | 29 | ## EXAMPLES 30 | 31 | ### -------------------------- EXAMPLE 1 -------------------------- 32 | ``` 33 | $testfile = 'C:\temp\test.ps1' 34 | ``` 35 | 36 | PS \> $test = Get-Content $testfile -raw 37 | PS \> $test | Format-ScriptExpandFunctionBlocks | clip 38 | 39 | Description 40 | ----------- 41 | Takes C:\temp\test.ps1 as input, expands code blocks and places the result in the clipboard. 42 | 43 | ## PARAMETERS 44 | 45 | ### -Code 46 | Multiline or piped lines of code to process. 47 | 48 | ```yaml 49 | Type: String[] 50 | Parameter Sets: (All) 51 | Aliases: 52 | 53 | Required: True 54 | Position: 1 55 | Default value: 56 | Accept pipeline input: True (ByValue) 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### -DontExpandSingleLineBlocks 61 | Skip expansion of a codeblock if it only has a single line. 62 | 63 | ```yaml 64 | Type: SwitchParameter 65 | Parameter Sets: (All) 66 | Aliases: 67 | 68 | Required: False 69 | Position: 2 70 | Default value: False 71 | Accept pipeline input: False 72 | Accept wildcard characters: False 73 | ``` 74 | 75 | ### -SkipPostProcessingValidityCheck 76 | After modifications have been made a check will be performed that the code has no errors. 77 | Use this switch to bypass this check 78 | (This is not recommended!) 79 | 80 | ```yaml 81 | Type: SwitchParameter 82 | Parameter Sets: (All) 83 | Aliases: 84 | 85 | Required: False 86 | Position: 3 87 | Default value: False 88 | Accept pipeline input: False 89 | Accept wildcard characters: False 90 | ``` 91 | 92 | ## INPUTS 93 | 94 | ## OUTPUTS 95 | 96 | ## NOTES 97 | Author: Zachary Loeber 98 | Site: http://www.the-little-things.net/ 99 | Requires: Powershell 3.0 100 | 101 | Version History 102 | 1.0.0 - Initial release 103 | 1.0.1 - Fixed awful bug that spit out code without the function declaration (whoops) 104 | 105 | ## RELATED LINKS 106 | 107 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 108 | 109 | [http://www.the-little-things.net](http://www.the-little-things.net) 110 | 111 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptExpandNamedBlocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandNamedBlocks 8 | ## SYNOPSIS 9 | Expand any named code blocks found in curly braces from inline to a more readable format. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandNamedBlocks [-Code] [-DontExpandSingleLineBlocks] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Expand any named code blocks found in curly braces from inline to a more readable format. 20 | So this: 21 | begin { Write-Output $_ } 22 | 23 | becomes this: 24 | 25 | begin 26 | { 27 | Write-Output $_ 28 | } 29 | 30 | ## EXAMPLES 31 | 32 | ### -------------------------- EXAMPLE 1 -------------------------- 33 | ``` 34 | $testfile = 'C:\temp\test.ps1' 35 | ``` 36 | 37 | PS \> $test = Get-Content $testfile -raw 38 | PS \> $test | Format-ScriptExpandNamedBlocks | clip 39 | 40 | Description 41 | ----------- 42 | Takes C:\temp\test.ps1 as input, expands code blocks and places the result in the clipboard. 43 | 44 | ## PARAMETERS 45 | 46 | ### -Code 47 | Multiline or piped lines of code to process. 48 | 49 | ```yaml 50 | Type: String[] 51 | Parameter Sets: (All) 52 | Aliases: 53 | 54 | Required: True 55 | Position: 1 56 | Default value: 57 | Accept pipeline input: True (ByValue) 58 | Accept wildcard characters: False 59 | ``` 60 | 61 | ### -DontExpandSingleLineBlocks 62 | Skip expansion of a codeblock if it only has a single line. 63 | 64 | ```yaml 65 | Type: SwitchParameter 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: False 70 | Position: 2 71 | Default value: False 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### -SkipPostProcessingValidityCheck 77 | After modifications have been made a check will be performed that the code has no errors. 78 | Use this switch to bypass this check 79 | (This is not recommended!) 80 | 81 | ```yaml 82 | Type: SwitchParameter 83 | Parameter Sets: (All) 84 | Aliases: 85 | 86 | Required: False 87 | Position: 3 88 | Default value: False 89 | Accept pipeline input: False 90 | Accept wildcard characters: False 91 | ``` 92 | 93 | ## INPUTS 94 | 95 | ## OUTPUTS 96 | 97 | ## NOTES 98 | Author: Zachary Loeber 99 | Site: http://www.the-little-things.net/ 100 | Requires: Powershell 3.0 101 | 102 | Version History 103 | 1.0.0 - Initial release 104 | 105 | ## RELATED LINKS 106 | 107 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 108 | 109 | [http://www.the-little-things.net](http://www.the-little-things.net) 110 | 111 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptExpandParameterBlocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandParameterBlocks 8 | ## SYNOPSIS 9 | Expand any parameter blocks from inline to a more readable format. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandParameterBlocks [-Code] [-SplitParameterTypeNames] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Expand any parameter blocks from inline to a more readable format. 20 | 21 | ## EXAMPLES 22 | 23 | ### -------------------------- EXAMPLE 1 -------------------------- 24 | ``` 25 | $testfile = 'C:\temp\test.ps1' 26 | ``` 27 | 28 | PS \> $test = Get-Content $testfile -raw 29 | PS \> $test | Format-ScriptExpandParameterBlocks | clip 30 | 31 | Description 32 | ----------- 33 | Takes C:\temp\test.ps1 as input, expands parameter blocks and places the result in the clipboard. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multiline or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SplitParameterTypeNames 53 | Place Parameter typenames on their own line. 54 | 55 | ```yaml 56 | Type: SwitchParameter 57 | Parameter Sets: (All) 58 | Aliases: 59 | 60 | Required: False 61 | Position: 2 62 | Default value: False 63 | Accept pipeline input: False 64 | Accept wildcard characters: False 65 | ``` 66 | 67 | ### -SkipPostProcessingValidityCheck 68 | After modifications have been made a check will be performed that the code has no errors. 69 | Use this switch to bypass this check 70 | (This is not recommended!) 71 | 72 | ```yaml 73 | Type: SwitchParameter 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: 3 79 | Default value: False 80 | Accept pipeline input: False 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ## INPUTS 85 | 86 | ## OUTPUTS 87 | 88 | ## NOTES 89 | Author: Zachary Loeber 90 | Site: http://www.the-little-things.net/ 91 | Requires: Powershell 3.0 92 | 93 | Version History 94 | 1.0.0 - Initial release 95 | 1.0.1 - fixed logic for embedded parameter blocks, added more verbose output. 96 | 1.0.1 - Fixed instance where parameter types were being shortened. 97 | 98 | ## RELATED LINKS 99 | 100 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 101 | 102 | [http://www.the-little-things.net](http://www.the-little-things.net) 103 | 104 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptExpandStatementBlocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandStatementBlocks 8 | ## SYNOPSIS 9 | Expand any statement code blocks found in curly braces from inline to a more readable format. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandStatementBlocks [-Code] [-DontExpandSingleLineBlocks] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Expand any statement code blocks found in curly braces from inline to a more readable format. 20 | So this: 21 | if ($a) { Write-Output $true } 22 | 23 | becomes this: 24 | 25 | if ($a) 26 | { 27 | Write-Output $true 28 | } 29 | 30 | ## EXAMPLES 31 | 32 | ### -------------------------- EXAMPLE 1 -------------------------- 33 | ``` 34 | $testfile = 'C:\temp\test.ps1' 35 | ``` 36 | 37 | PS \> $test = Get-Content $testfile -raw 38 | PS \> $test | Format-ScriptExpandStatementBlocks | clip 39 | 40 | Description 41 | ----------- 42 | Takes C:\temp\test.ps1 as input, expands code blocks and places the result in the clipboard. 43 | 44 | ## PARAMETERS 45 | 46 | ### -Code 47 | Multiline or piped lines of code to process. 48 | 49 | ```yaml 50 | Type: String[] 51 | Parameter Sets: (All) 52 | Aliases: 53 | 54 | Required: True 55 | Position: 1 56 | Default value: 57 | Accept pipeline input: True (ByValue) 58 | Accept wildcard characters: False 59 | ``` 60 | 61 | ### -DontExpandSingleLineBlocks 62 | Skip expansion of a codeblock if it only has a single line. 63 | 64 | ```yaml 65 | Type: SwitchParameter 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: False 70 | Position: 2 71 | Default value: False 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### -SkipPostProcessingValidityCheck 77 | After modifications have been made a check will be performed that the code has no errors. 78 | Use this switch to bypass this check 79 | (This is not recommended!) 80 | 81 | ```yaml 82 | Type: SwitchParameter 83 | Parameter Sets: (All) 84 | Aliases: 85 | 86 | Required: False 87 | Position: 3 88 | Default value: False 89 | Accept pipeline input: False 90 | Accept wildcard characters: False 91 | ``` 92 | 93 | ## INPUTS 94 | 95 | ## OUTPUTS 96 | 97 | ## NOTES 98 | Author: Zachary Loeber 99 | Site: http://www.the-little-things.net/ 100 | Requires: Powershell 3.0 101 | 102 | Version History 103 | 1.0.0 - Initial release 104 | 105 | ## RELATED LINKS 106 | 107 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 108 | 109 | [http://www.the-little-things.net](http://www.the-little-things.net) 110 | 111 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptExpandTypeAccelerators.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandTypeAccelerators 8 | ## SYNOPSIS 9 | Converts shorthand type accelerators to their full name. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandTypeAccelerators [-Code] [-AllTypes] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Converts shorthand type accelerators to their full name. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptExpandTypeAccelerators -AllTypes | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, converts all type accelerators to their full name and places the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multi-line or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -AllTypes 53 | Include system type accelerators. 54 | 55 | ```yaml 56 | Type: SwitchParameter 57 | Parameter Sets: (All) 58 | Aliases: 59 | 60 | Required: False 61 | Position: 2 62 | Default value: False 63 | Accept pipeline input: False 64 | Accept wildcard characters: False 65 | ``` 66 | 67 | ### -SkipPostProcessingValidityCheck 68 | After modifications have been made a check will be performed that the code has no errors. 69 | Use this switch to bypass this check 70 | (This is not recommended!) 71 | 72 | ```yaml 73 | Type: SwitchParameter 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: 3 79 | Default value: False 80 | Accept pipeline input: False 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ## INPUTS 85 | 86 | ## OUTPUTS 87 | 88 | ## NOTES 89 | Author: Zachary Loeber 90 | Site: http://www.the-little-things.net/ 91 | Requires: Powershell 3.0 92 | 93 | Version History 94 | 1.0.0 - Initial release 95 | 96 | ## RELATED LINKS 97 | 98 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 99 | 100 | [http://www.the-little-things.net](http://www.the-little-things.net) 101 | 102 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptFormatCodeIndentation.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptFormatCodeIndentation 8 | ## SYNOPSIS 9 | Indents code blocks based on their level. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptFormatCodeIndentation [-Code] [[-Depth] ] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Indents code blocks based on their level. 19 | This is usually the last function you will run if using this module to beautify your code. 20 | 21 | ## EXAMPLES 22 | 23 | ### -------------------------- EXAMPLE 1 -------------------------- 24 | ``` 25 | $testfile = 'C:\temp\test.ps1' 26 | ``` 27 | 28 | PS \> $test = Get-Content $testfile -raw 29 | PS \> $test | Format-ScriptFormatCodeIndentation | clip 30 | 31 | Description 32 | ----------- 33 | Takes C:\temp\test.ps1 as input, indents all code and places the result in the clipboard 34 | to be pasted elsewhere for review. 35 | 36 | ## PARAMETERS 37 | 38 | ### -Code 39 | Multi-line or piped lines of code to process. 40 | 41 | ```yaml 42 | Type: String[] 43 | Parameter Sets: (All) 44 | Aliases: 45 | 46 | Required: True 47 | Position: 1 48 | Default value: 49 | Accept pipeline input: True (ByValue) 50 | Accept wildcard characters: False 51 | ``` 52 | 53 | ### -Depth 54 | How many spaces to indent per level. 55 | Default is 4. 56 | 57 | ```yaml 58 | Type: Int32 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: 4 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### -SkipPostProcessingValidityCheck 70 | After modifications have been made a check will be performed that the code has no errors. 71 | Use this switch to bypass this check 72 | (This is not recommended!) 73 | 74 | ```yaml 75 | Type: SwitchParameter 76 | Parameter Sets: (All) 77 | Aliases: 78 | 79 | Required: False 80 | Position: 3 81 | Default value: False 82 | Accept pipeline input: False 83 | Accept wildcard characters: False 84 | ``` 85 | 86 | ## INPUTS 87 | 88 | ## OUTPUTS 89 | 90 | ## NOTES 91 | Author: Zachary Loeber 92 | Site: http://www.the-little-things.net/ 93 | Requires: Powershell 3.0 94 | Modified a little bit from here: http://www.powershellmagazine.com/2013/09/03/pstip-tabify-your-script/ 95 | 96 | Version History 97 | 1.0.0 - Initial release 98 | 99 | ## RELATED LINKS 100 | 101 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 102 | 103 | [http://www.the-little-things.net](http://www.the-little-things.net) 104 | 105 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptFormatCommandNames.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptFormatCommandNames 8 | ## SYNOPSIS 9 | Converts all found commands to proper case (aka. 10 | PascalCased). 11 | 12 | ## SYNTAX 13 | 14 | ``` 15 | Format-ScriptFormatCommandNames [-Code] [-ExpandAliases] [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Converts all found commands to proper case (aka. 20 | PascalCased). 21 | 22 | ## EXAMPLES 23 | 24 | ### -------------------------- EXAMPLE 1 -------------------------- 25 | ``` 26 | $testfile = 'C:\temp\test.ps1' 27 | ``` 28 | 29 | PS \> $test = Get-Content $testfile -raw 30 | PS \> $test | Format-ScriptFormatCommandNames | clip 31 | 32 | Description 33 | ----------- 34 | Takes C:\temp\test.ps1 as input, PascalCase formats any commands found and places the result in the clipboard 35 | to be pasted elsewhere for review. 36 | 37 | ## PARAMETERS 38 | 39 | ### -Code 40 | Multi-line or piped lines of code to process. 41 | 42 | ```yaml 43 | Type: String[] 44 | Parameter Sets: (All) 45 | Aliases: 46 | 47 | Required: True 48 | Position: 1 49 | Default value: 50 | Accept pipeline input: True (ByValue) 51 | Accept wildcard characters: False 52 | ``` 53 | 54 | ### -ExpandAliases 55 | Expand any found aliases. 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### -SkipPostProcessingValidityCheck 70 | After modifications have been made a check will be performed that the code has no errors. 71 | Use this switch to bypass this check 72 | (This is not recommended!) 73 | 74 | ```yaml 75 | Type: SwitchParameter 76 | Parameter Sets: (All) 77 | Aliases: 78 | 79 | Required: False 80 | Position: 3 81 | Default value: False 82 | Accept pipeline input: False 83 | Accept wildcard characters: False 84 | ``` 85 | 86 | ## INPUTS 87 | 88 | ## OUTPUTS 89 | 90 | ## NOTES 91 | Author: Zachary Loeber 92 | Site: http://www.the-little-things.net/ 93 | Requires: Powershell 3.0 94 | 95 | Version History 96 | 1.0.0 - Initial release 97 | 1.0.1 - Fixed improper handling of ? 98 | alias 99 | - Added more verbose output 100 | 101 | ## RELATED LINKS 102 | 103 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 104 | 105 | [http://www.the-little-things.net](http://www.the-little-things.net) 106 | 107 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptFormatTypeNames.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptFormatTypeNames 8 | ## SYNOPSIS 9 | Converts typenames within code to be properly formated. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptFormatTypeNames [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Converts typenames within code to be properly formated 19 | (ie. 20 | \[bool\] becomes \[Bool\] and \[system.string\] becomes \[System.String\]). 21 | 22 | ## EXAMPLES 23 | 24 | ### -------------------------- EXAMPLE 1 -------------------------- 25 | ``` 26 | $testfile = 'C:\temp\test.ps1' 27 | ``` 28 | 29 | PS \> $test = Get-Content $testfile -raw 30 | PS \> $test | Format-ScriptFormatTypeNames | clip 31 | 32 | Description 33 | ----------- 34 | Takes C:\temp\test.ps1 as input, formats any typenames found and places the result in the clipboard 35 | to be pasted elsewhere for review. 36 | 37 | ## PARAMETERS 38 | 39 | ### -Code 40 | Multiline or piped lines of code to process. 41 | 42 | ```yaml 43 | Type: String[] 44 | Parameter Sets: (All) 45 | Aliases: 46 | 47 | Required: True 48 | Position: 1 49 | Default value: 50 | Accept pipeline input: True (ByValue) 51 | Accept wildcard characters: False 52 | ``` 53 | 54 | ### -SkipPostProcessingValidityCheck 55 | After modifications have been made a check will be performed that the code has no errors. 56 | Use this switch to bypass this check 57 | (This is not recommended!) 58 | 59 | ```yaml 60 | Type: SwitchParameter 61 | Parameter Sets: (All) 62 | Aliases: 63 | 64 | Required: False 65 | Position: 2 66 | Default value: False 67 | Accept pipeline input: False 68 | Accept wildcard characters: False 69 | ``` 70 | 71 | ## INPUTS 72 | 73 | ## OUTPUTS 74 | 75 | ## NOTES 76 | Author: Zachary Loeber 77 | Site: http://www.the-little-things.net/ 78 | Requires: Powershell 3.0 79 | 80 | Version History 81 | 1.0.0 - Initial release 82 | 83 | ## RELATED LINKS 84 | 85 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 86 | 87 | [http://www.the-little-things.net](http://www.the-little-things.net) 88 | 89 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptPadExpressions.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptPadExpressions 8 | ## SYNOPSIS 9 | Pads powershell expressions with single spaces. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptPadExpressions [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Pads powershell expressions with single spaces. 19 | Expressions padded include +,-,/,%, and * 20 | 21 | ## EXAMPLES 22 | 23 | ### -------------------------- EXAMPLE 1 -------------------------- 24 | ``` 25 | $testfile = 'C:\temp\test.ps1' 26 | ``` 27 | 28 | PS \> $test = Get-Content $testfile -raw 29 | PS \> $test | Format-ScriptPadExpressions | clip 30 | 31 | Description 32 | ----------- 33 | Takes C:\temp\test.ps1 as input, pads any expressions found with single spaces and places the result in the clipboard 34 | to be pasted elsewhere for review. 35 | 36 | ## PARAMETERS 37 | 38 | ### -Code 39 | Multi-line or piped lines of code to process. 40 | 41 | ```yaml 42 | Type: String[] 43 | Parameter Sets: (All) 44 | Aliases: 45 | 46 | Required: True 47 | Position: 1 48 | Default value: 49 | Accept pipeline input: True (ByValue) 50 | Accept wildcard characters: False 51 | ``` 52 | 53 | ### -SkipPostProcessingValidityCheck 54 | After modifications have been made a check will be performed that the code has no errors. 55 | Use this switch to bypass this check 56 | (This is not recommended!) 57 | 58 | ```yaml 59 | Type: SwitchParameter 60 | Parameter Sets: (All) 61 | Aliases: 62 | 63 | Required: False 64 | Position: 2 65 | Default value: False 66 | Accept pipeline input: False 67 | Accept wildcard characters: False 68 | ``` 69 | 70 | ## INPUTS 71 | 72 | ## OUTPUTS 73 | 74 | ## NOTES 75 | Author: Zachary Loeber 76 | Site: http://www.the-little-things.net/ 77 | Requires: Powershell 3.0 78 | 79 | Version History 80 | 1.0.0 - Initial release 81 | 82 | ## RELATED LINKS 83 | 84 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 85 | 86 | [http://www.the-little-things.net](http://www.the-little-things.net) 87 | 88 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptPadOperators.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptPadOperators 8 | ## SYNOPSIS 9 | Pads powershell assignment operators with single spaces. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptPadOperators [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Pads powershell assignment operators with single spaces. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptPadOperators | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, spaced all assignment operators and puts the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multi-line or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SkipPostProcessingValidityCheck 53 | After modifications have been made a check will be performed that the code has no errors. 54 | Use this switch to bypass this check 55 | (This is not recommended!) 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ## INPUTS 70 | 71 | ## OUTPUTS 72 | 73 | ## NOTES 74 | Author: Zachary Loeber 75 | Site: http://www.the-little-things.net/ 76 | Requires: Powershell 3.0 77 | 78 | Version History 79 | 1.0.0 - Initial release 80 | 81 | ## RELATED LINKS 82 | 83 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 84 | 85 | [http://www.the-little-things.net](http://www.the-little-things.net) 86 | 87 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptReduceLineLength.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptReduceLineLength 8 | ## SYNOPSIS 9 | Attempt to shorten long lines if possible. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptReduceLineLength [-Code] [[-Length] ] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Attempt to shorten long lines if possible. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptReduceLineLength | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, formats as the function defines and places the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multiline or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -Length 53 | Number of characters to shorten long lines to. 54 | Default is 115 characters as this is best practice. 55 | 56 | ```yaml 57 | Type: Int32 58 | Parameter Sets: (All) 59 | Aliases: 60 | 61 | Required: False 62 | Position: 2 63 | Default value: 115 64 | Accept pipeline input: False 65 | Accept wildcard characters: False 66 | ``` 67 | 68 | ### -SkipPostProcessingValidityCheck 69 | After modifications have been made a check will be performed that the code has no errors. 70 | Use this switch to bypass this check 71 | (This is not recommended!) 72 | 73 | ```yaml 74 | Type: SwitchParameter 75 | Parameter Sets: (All) 76 | Aliases: 77 | 78 | Required: False 79 | Position: 3 80 | Default value: False 81 | Accept pipeline input: False 82 | Accept wildcard characters: False 83 | ``` 84 | 85 | ## INPUTS 86 | 87 | ## OUTPUTS 88 | 89 | ## NOTES 90 | Author: Zachary Loeber 91 | Site: http://www.the-little-things.net/ 92 | Requires: Powershell 3.0 93 | 94 | Version History 95 | 1.0.0 - Initial release 96 | 97 | ## RELATED LINKS 98 | 99 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 100 | 101 | [http://www.the-little-things.net](http://www.the-little-things.net) 102 | 103 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptRemoveStatementSeparators.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptRemoveStatementSeparators 8 | ## SYNOPSIS 9 | Finds all statement separators (semicolons) not in for loops and converts them to newlines. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptRemoveStatementSeparators [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Finds all statement separators (semicolons) not in for loops and converts them to newlines. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-RemoveStatementSeparators | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, remove statement separators and puts the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multi-line or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SkipPostProcessingValidityCheck 53 | After modifications have been made a check will be performed that the code has no errors. 54 | Use this switch to bypass this check 55 | (This is not recommended!) 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ## INPUTS 70 | 71 | ## OUTPUTS 72 | 73 | ## NOTES 74 | Author: Zachary Loeber 75 | Site: http://www.the-little-things.net/ 76 | Requires: Powershell 3.0 77 | 78 | Version History 79 | 1.0.0 - Initial release 80 | 81 | ## RELATED LINKS 82 | 83 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 84 | 85 | [http://www.the-little-things.net](http://www.the-little-things.net) 86 | 87 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptRemoveSuperfluousSpaces.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptRemoveSuperfluousSpaces 8 | ## SYNOPSIS 9 | Removes superfluous spaces at the end of individual lines of code. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptRemoveSuperfluousSpaces [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Removes superfluous spaces at the end of individual lines of code. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | $test = Get-Content $testfile -raw 28 | $test | Format-ScriptRemoveSuperfluousSpaces | Clip 29 | 30 | Description 31 | ----------- 32 | Removes all additional spaces and whitespace from the end of every non-herestring/comment in C:\temp\test.ps1 33 | 34 | ## PARAMETERS 35 | 36 | ### -Code 37 | Multiple lines of code to analyze. 38 | Ignores all herestrings. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SkipPostProcessingValidityCheck 53 | After modifications have been made a check will be performed that the code has no errors. 54 | Use this switch to bypass this check 55 | (This is not recommended!) 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ## INPUTS 70 | 71 | ## OUTPUTS 72 | 73 | ## NOTES 74 | Author: Zachary Loeber 75 | Site: http://www.the-little-things.net/ 76 | 77 | 1.0.0 - Initial release 78 | 79 | ## RELATED LINKS 80 | 81 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 82 | 83 | [http://www.the-little-things.net](http://www.the-little-things.net) 84 | 85 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptReplaceHereStrings.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptReplaceHereStrings 8 | ## SYNOPSIS 9 | Replace here strings with variable created equivalents. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptReplaceHereStrings [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Replace here strings with variable created equivalents. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptReplaceHereStrings | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, formats as the function defines and places the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multiple lines of code to analyze 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SkipPostProcessingValidityCheck 53 | After modifications have been made a check will be performed that the code has no errors. 54 | Use this switch to bypass this check 55 | (This is not recommended!) 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ## INPUTS 70 | 71 | ## OUTPUTS 72 | 73 | ## NOTES 74 | Author: Zachary Loeber 75 | Site: http://www.the-little-things.net/ 76 | Requires: Powershell 3.0 77 | 78 | Version History 79 | 1.0.0 - Initial release 80 | 1.0.1 - Fixed some replacements based on if the string is expandable or not. 81 | - Changed output to be all one assignment rather than multiple assignments 82 | 83 | ## RELATED LINKS 84 | 85 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 86 | 87 | [http://www.the-little-things.net](http://www.the-little-things.net) 88 | 89 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptReplaceInvalidCharacters.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptReplaceInvalidCharacters 8 | ## SYNOPSIS 9 | Find and replaces invalid characters. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptReplaceInvalidCharacters [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Find and replaces invalid characters. 19 | These are often picked up from copying directly from blogging platforms. 20 | Although the scripts seem to 21 | run without issue most of the time they still look different enough to me to be irritating. 22 | So the following characters are replaced if they are not in a here string or comment: 23 | " becomes " 24 | " becomes " 25 | ' becomes ' (This is NOT the same as the line continuation character, the backtick, even if it looks the same in many editors) 26 | ' becomes ' 27 | 28 | ## EXAMPLES 29 | 30 | ### -------------------------- EXAMPLE 1 -------------------------- 31 | ``` 32 | $testfile = 'C:\temp\test.ps1' 33 | ``` 34 | 35 | PS \> $test = Get-Content $testfile -raw 36 | PS \> $test | Format-ScriptReplaceInvalidCharacters 37 | 38 | Description 39 | ----------- 40 | Takes C:\temp\test.ps1 as input, replaces invalid characters and places the result in the console window. 41 | 42 | ## PARAMETERS 43 | 44 | ### -Code 45 | Multiline or piped lines of code to process. 46 | 47 | ```yaml 48 | Type: String[] 49 | Parameter Sets: (All) 50 | Aliases: 51 | 52 | Required: True 53 | Position: 1 54 | Default value: 55 | Accept pipeline input: True (ByValue) 56 | Accept wildcard characters: False 57 | ``` 58 | 59 | ### -SkipPostProcessingValidityCheck 60 | After modifications have been made a check will be performed that the code has no errors. 61 | Use this switch to bypass this check 62 | (This is not recommended!) 63 | 64 | ```yaml 65 | Type: SwitchParameter 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: False 70 | Position: 2 71 | Default value: False 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ## INPUTS 77 | 78 | ## OUTPUTS 79 | 80 | ## NOTES 81 | Author: Zachary Loeber 82 | Site: http://www.the-little-things.net/ 83 | Requires: Powershell 3.0 84 | 85 | Version History 86 | 1.0.0 - Initial release 87 | 88 | ## RELATED LINKS 89 | 90 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 91 | 92 | [http://www.the-little-things.net](http://www.the-little-things.net) 93 | 94 | -------------------------------------------------------------------------------- /release/1.4.0/docs/Format-ScriptTestCodeBlock.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptTestCodeBlock 8 | ## SYNOPSIS 9 | Validates there are no script parsing errors in a script. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptTestCodeBlock [-Code] [-ShowParsingErrors] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Validates there are no script parsing errors in a script. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptTestCodeBlock 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input and validates if the code is valid or not. 33 | Returns $true if it is, $false if it is not. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multiline or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -ShowParsingErrors 53 | Display parsing errors if found. 54 | 55 | ```yaml 56 | Type: SwitchParameter 57 | Parameter Sets: (All) 58 | Aliases: 59 | 60 | Required: False 61 | Position: 2 62 | Default value: False 63 | Accept pipeline input: False 64 | Accept wildcard characters: False 65 | ``` 66 | 67 | ## INPUTS 68 | 69 | ## OUTPUTS 70 | 71 | ## NOTES 72 | Author: Zachary Loeber 73 | Site: http://www.the-little-things.net/ 74 | Requires: Powershell 3.0 75 | 76 | Version History 77 | 1.0.0 - Initial release 78 | 79 | ## RELATED LINKS 80 | 81 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 82 | 83 | [http://www.the-little-things.net](http://www.the-little-things.net) 84 | 85 | -------------------------------------------------------------------------------- /release/1.4.0/docs/FormatPowershellCode.md: -------------------------------------------------------------------------------- 1 | --- 2 | Module Name: FormatPowershellCode 3 | Module Guid: dcfbce3c-18be-4775-b98d-4431d4fb9e08 4 | Download Help Link: https://github.com/zloeber/FormatPowershellCode/release/FormatPowershellCode/docs/FormatPowershellCode.md 5 | Help Version: 1.4.0 6 | Locale: en-US 7 | --- 8 | 9 | # FormatPowershellCode Module 10 | ## Description 11 | A set of functions for standardizing and reformatting PowerShell script code. 12 | 13 | ## FormatPowershellCode Cmdlets 14 | ### [Format-ScriptCondenseEnclosures](Format-ScriptCondenseEnclosures.md) 15 | Moves specified beginning enclosure types to the end of the prior line if found to be on its own line. 16 | 17 | ### [Format-ScriptExpandFunctionBlocks](Format-ScriptExpandFunctionBlocks.md) 18 | Expand any function code blocks found in curly braces from inline to a more readable format. 19 | 20 | ### [Format-ScriptExpandNamedBlocks](Format-ScriptExpandNamedBlocks.md) 21 | Expand any named code blocks found in curly braces from inline to a more readable format. 22 | 23 | ### [Format-ScriptExpandParameterBlocks](Format-ScriptExpandParameterBlocks.md) 24 | Expand any parameter blocks from inline to a more readable format. 25 | 26 | ### [Format-ScriptExpandStatementBlocks](Format-ScriptExpandStatementBlocks.md) 27 | Expand any statement code blocks found in curly braces from inline to a more readable format. 28 | 29 | ### [Format-ScriptExpandTypeAccelerators](Format-ScriptExpandTypeAccelerators.md) 30 | Converts shorthand type accelerators to their full name. 31 | 32 | ### [Format-ScriptFormatCodeIndentation](Format-ScriptFormatCodeIndentation.md) 33 | Indents code blocks based on their level. 34 | 35 | ### [Format-ScriptFormatCommandNames](Format-ScriptFormatCommandNames.md) 36 | Converts all found commands to proper case (aka. PascalCased). 37 | 38 | ### [Format-ScriptFormatTypeNames](Format-ScriptFormatTypeNames.md) 39 | Converts typenames within code to be properly formated. 40 | 41 | ### [Format-ScriptPadExpressions](Format-ScriptPadExpressions.md) 42 | Pads powershell expressions with single spaces. 43 | 44 | ### [Format-ScriptPadOperators](Format-ScriptPadOperators.md) 45 | Pads powershell assignment operators with single spaces. 46 | 47 | ### [Format-ScriptReduceLineLength](Format-ScriptReduceLineLength.md) 48 | Attempt to shorten long lines if possible. 49 | 50 | ### [Format-ScriptRemoveStatementSeparators](Format-ScriptRemoveStatementSeparators.md) 51 | Finds all statement separators (semicolons) not in for loops and converts them to newlines. 52 | 53 | ### [Format-ScriptRemoveSuperfluousSpaces](Format-ScriptRemoveSuperfluousSpaces.md) 54 | Removes superfluous spaces at the end of individual lines of code. 55 | 56 | ### [Format-ScriptReplaceHereStrings](Format-ScriptReplaceHereStrings.md) 57 | Replace here strings with variable created equivalents. 58 | 59 | ### [Format-ScriptReplaceInvalidCharacters](Format-ScriptReplaceInvalidCharacters.md) 60 | Find and replaces invalid characters. 61 | 62 | ### [Format-ScriptTestCodeBlock](Format-ScriptTestCodeBlock.md) 63 | Validates there are no script parsing errors in a script. 64 | 65 | 66 | -------------------------------------------------------------------------------- /release/1.4.0/en-US/FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_HelpInfo.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | https://github.com/zloeber/FormatPowershellCode/release/FormatPowershellCode/docs/FormatPowershellCode.md 4 | 5 | 6 | en-US 7 | 1.4.0 8 | 9 | 10 | -------------------------------------------------------------------------------- /release/1.4.0/en-US/FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_en-US_helpcontent.cab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zloeber/FormatPowershellCode/a8b1d2edec3ed074fa464d4f881556c6dc9e784e/release/1.4.0/en-US/FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_en-US_helpcontent.cab -------------------------------------------------------------------------------- /release/1.4.0/en-US/about_FormatPowershellCode.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_FormatPowerShellCode 3 | 4 | SHORT DESCRIPTION 5 | A set of functions for standardizing and reformatting PowerShell script code. 6 | 7 | LONG DESCRIPTION 8 | A set of functions for standardizing and reformatting PowerShell script code. 9 | 10 | EXAMPLES 11 | import-module .\FormatPowershellCode.psm1 12 | get-content .\tests\testcase-codeblockexpansion.ps1 -raw | 13 | Format-ScriptRemoveStatementSeparators | 14 | Format-ScriptExpandFunctionBlocks | 15 | Format-ScriptExpandNamedBlocks | 16 | Format-ScriptExpandParameterBlocks | 17 | Format-ScriptExpandStatementBlocks | 18 | Format-ScriptFormatCodeIndentation | 19 | clip 20 | 21 | KEYWORDS 22 | Code Formatter, PowerShell Style 23 | 24 | SEE ALSO 25 | NA -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptCondenseEnclosures.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptCondenseEnclosures 8 | ## SYNOPSIS 9 | Moves specified beginning enclosure types to the end of the prior line if found to be on its own line. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptCondenseEnclosures [-Code] [[-EnclosureStart] ] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Moves specified beginning enclosure types to the end of the prior line if found to be on its own line. 20 | 21 | ## EXAMPLES 22 | 23 | ### -------------------------- EXAMPLE 1 -------------------------- 24 | ``` 25 | $test = Get-Content -Raw -Path 'C:\testcases\test-pad-operators.ps1' 26 | ``` 27 | 28 | $test | Format-ScriptCondenseEnclosures | clip 29 | 30 | Description 31 | ----------- 32 | Moves all beginning enclosure characters to the prior line if found to be sitting at the beginning of a line. 33 | 34 | ## PARAMETERS 35 | 36 | ### -Code 37 | Multiple lines of code to analyze 38 | 39 | ```yaml 40 | Type: String[] 41 | Parameter Sets: (All) 42 | Aliases: 43 | 44 | Required: True 45 | Position: 1 46 | Default value: 47 | Accept pipeline input: True (ByValue) 48 | Accept wildcard characters: False 49 | ``` 50 | 51 | ### -EnclosureStart 52 | Array of starting enclosure characters to process (default is (, {, @(, and @{) 53 | 54 | ```yaml 55 | Type: String[] 56 | Parameter Sets: (All) 57 | Aliases: 58 | 59 | Required: False 60 | Position: 2 61 | Default value: @('{','(','@{','@(') 62 | Accept pipeline input: False 63 | Accept wildcard characters: False 64 | ``` 65 | 66 | ### -SkipPostProcessingValidityCheck 67 | After modifications have been made a check will be performed that the code has no errors. 68 | Use this switch to bypass this check (This is not recommended!) 69 | 70 | ```yaml 71 | Type: SwitchParameter 72 | Parameter Sets: (All) 73 | Aliases: 74 | 75 | Required: False 76 | Position: 3 77 | Default value: False 78 | Accept pipeline input: False 79 | Accept wildcard characters: False 80 | ``` 81 | 82 | ## INPUTS 83 | 84 | ## OUTPUTS 85 | 86 | ## NOTES 87 | This function fails to 'condense' anything really complex and probably shouldn't even be used... 88 | 89 | Author: Zachary Loeber 90 | Site: http://www.the-little-things.net/ 91 | 92 | 1.0.0 - 01/25/2015 93 | - Initial release 94 | 95 | ## RELATED LINKS 96 | 97 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 98 | 99 | [http://www.the-little-things.net](http://www.the-little-things.net) 100 | 101 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptExpandFunctionBlocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandFunctionBlocks 8 | ## SYNOPSIS 9 | Expand any function code blocks found in curly braces from inline to a more readable format. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandFunctionBlocks [-Code] [-DontExpandSingleLineBlocks] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Expand any function code blocks found in curly braces from inline to a more readable format. 20 | So this: 21 | function testfunction { Write-Output $_ } 22 | 23 | becomes this: 24 | function testfunction 25 | { 26 | Write-Output $_ 27 | } 28 | 29 | ## EXAMPLES 30 | 31 | ### -------------------------- EXAMPLE 1 -------------------------- 32 | ``` 33 | $testfile = 'C:\temp\test.ps1' 34 | ``` 35 | 36 | PS \> $test = Get-Content $testfile -raw 37 | PS \> $test | Format-ScriptExpandFunctionBlocks | clip 38 | 39 | Description 40 | ----------- 41 | Takes C:\temp\test.ps1 as input, expands code blocks and places the result in the clipboard. 42 | 43 | ## PARAMETERS 44 | 45 | ### -Code 46 | Multiline or piped lines of code to process. 47 | 48 | ```yaml 49 | Type: String[] 50 | Parameter Sets: (All) 51 | Aliases: 52 | 53 | Required: True 54 | Position: 1 55 | Default value: 56 | Accept pipeline input: True (ByValue) 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### -DontExpandSingleLineBlocks 61 | Skip expansion of a codeblock if it only has a single line. 62 | 63 | ```yaml 64 | Type: SwitchParameter 65 | Parameter Sets: (All) 66 | Aliases: 67 | 68 | Required: False 69 | Position: 2 70 | Default value: False 71 | Accept pipeline input: False 72 | Accept wildcard characters: False 73 | ``` 74 | 75 | ### -SkipPostProcessingValidityCheck 76 | After modifications have been made a check will be performed that the code has no errors. 77 | Use this switch to bypass this check 78 | (This is not recommended!) 79 | 80 | ```yaml 81 | Type: SwitchParameter 82 | Parameter Sets: (All) 83 | Aliases: 84 | 85 | Required: False 86 | Position: 3 87 | Default value: False 88 | Accept pipeline input: False 89 | Accept wildcard characters: False 90 | ``` 91 | 92 | ## INPUTS 93 | 94 | ## OUTPUTS 95 | 96 | ## NOTES 97 | Author: Zachary Loeber 98 | Site: http://www.the-little-things.net/ 99 | Requires: Powershell 3.0 100 | 101 | Version History 102 | 1.0.0 - Initial release 103 | 1.0.1 - Fixed awful bug that spit out code without the function declaration (whoops) 104 | 105 | ## RELATED LINKS 106 | 107 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 108 | 109 | [http://www.the-little-things.net](http://www.the-little-things.net) 110 | 111 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptExpandNamedBlocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandNamedBlocks 8 | ## SYNOPSIS 9 | Expand any named code blocks found in curly braces from inline to a more readable format. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandNamedBlocks [-Code] [-DontExpandSingleLineBlocks] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Expand any named code blocks found in curly braces from inline to a more readable format. 20 | So this: 21 | begin { Write-Output $_ } 22 | 23 | becomes this: 24 | 25 | begin 26 | { 27 | Write-Output $_ 28 | } 29 | 30 | ## EXAMPLES 31 | 32 | ### -------------------------- EXAMPLE 1 -------------------------- 33 | ``` 34 | $testfile = 'C:\temp\test.ps1' 35 | ``` 36 | 37 | PS \> $test = Get-Content $testfile -raw 38 | PS \> $test | Format-ScriptExpandNamedBlocks | clip 39 | 40 | Description 41 | ----------- 42 | Takes C:\temp\test.ps1 as input, expands code blocks and places the result in the clipboard. 43 | 44 | ## PARAMETERS 45 | 46 | ### -Code 47 | Multiline or piped lines of code to process. 48 | 49 | ```yaml 50 | Type: String[] 51 | Parameter Sets: (All) 52 | Aliases: 53 | 54 | Required: True 55 | Position: 1 56 | Default value: 57 | Accept pipeline input: True (ByValue) 58 | Accept wildcard characters: False 59 | ``` 60 | 61 | ### -DontExpandSingleLineBlocks 62 | Skip expansion of a codeblock if it only has a single line. 63 | 64 | ```yaml 65 | Type: SwitchParameter 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: False 70 | Position: 2 71 | Default value: False 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### -SkipPostProcessingValidityCheck 77 | After modifications have been made a check will be performed that the code has no errors. 78 | Use this switch to bypass this check 79 | (This is not recommended!) 80 | 81 | ```yaml 82 | Type: SwitchParameter 83 | Parameter Sets: (All) 84 | Aliases: 85 | 86 | Required: False 87 | Position: 3 88 | Default value: False 89 | Accept pipeline input: False 90 | Accept wildcard characters: False 91 | ``` 92 | 93 | ## INPUTS 94 | 95 | ## OUTPUTS 96 | 97 | ## NOTES 98 | Author: Zachary Loeber 99 | Site: http://www.the-little-things.net/ 100 | Requires: Powershell 3.0 101 | 102 | Version History 103 | 1.0.0 - Initial release 104 | 105 | ## RELATED LINKS 106 | 107 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 108 | 109 | [http://www.the-little-things.net](http://www.the-little-things.net) 110 | 111 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptExpandParameterBlocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandParameterBlocks 8 | ## SYNOPSIS 9 | Expand any parameter blocks from inline to a more readable format. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandParameterBlocks [-Code] [-SplitParameterTypeNames] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Expand any parameter blocks from inline to a more readable format. 20 | 21 | ## EXAMPLES 22 | 23 | ### -------------------------- EXAMPLE 1 -------------------------- 24 | ``` 25 | $testfile = 'C:\temp\test.ps1' 26 | ``` 27 | 28 | PS \> $test = Get-Content $testfile -raw 29 | PS \> $test | Format-ScriptExpandParameterBlocks | clip 30 | 31 | Description 32 | ----------- 33 | Takes C:\temp\test.ps1 as input, expands parameter blocks and places the result in the clipboard. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multiline or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SplitParameterTypeNames 53 | Place Parameter typenames on their own line. 54 | 55 | ```yaml 56 | Type: SwitchParameter 57 | Parameter Sets: (All) 58 | Aliases: 59 | 60 | Required: False 61 | Position: 2 62 | Default value: False 63 | Accept pipeline input: False 64 | Accept wildcard characters: False 65 | ``` 66 | 67 | ### -SkipPostProcessingValidityCheck 68 | After modifications have been made a check will be performed that the code has no errors. 69 | Use this switch to bypass this check 70 | (This is not recommended!) 71 | 72 | ```yaml 73 | Type: SwitchParameter 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: 3 79 | Default value: False 80 | Accept pipeline input: False 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ## INPUTS 85 | 86 | ## OUTPUTS 87 | 88 | ## NOTES 89 | Author: Zachary Loeber 90 | Site: http://www.the-little-things.net/ 91 | Requires: Powershell 3.0 92 | 93 | Version History 94 | 1.0.0 - Initial release 95 | 1.0.1 - fixed logic for embedded parameter blocks, added more verbose output. 96 | 1.0.1 - Fixed instance where parameter types were being shortened. 97 | 98 | ## RELATED LINKS 99 | 100 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 101 | 102 | [http://www.the-little-things.net](http://www.the-little-things.net) 103 | 104 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptExpandStatementBlocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandStatementBlocks 8 | ## SYNOPSIS 9 | Expand any statement code blocks found in curly braces from inline to a more readable format. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandStatementBlocks [-Code] [-DontExpandSingleLineBlocks] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Expand any statement code blocks found in curly braces from inline to a more readable format. 20 | So this: 21 | if ($a) { Write-Output $true } 22 | 23 | becomes this: 24 | 25 | if ($a) 26 | { 27 | Write-Output $true 28 | } 29 | 30 | ## EXAMPLES 31 | 32 | ### -------------------------- EXAMPLE 1 -------------------------- 33 | ``` 34 | $testfile = 'C:\temp\test.ps1' 35 | ``` 36 | 37 | PS \> $test = Get-Content $testfile -raw 38 | PS \> $test | Format-ScriptExpandStatementBlocks | clip 39 | 40 | Description 41 | ----------- 42 | Takes C:\temp\test.ps1 as input, expands code blocks and places the result in the clipboard. 43 | 44 | ## PARAMETERS 45 | 46 | ### -Code 47 | Multiline or piped lines of code to process. 48 | 49 | ```yaml 50 | Type: String[] 51 | Parameter Sets: (All) 52 | Aliases: 53 | 54 | Required: True 55 | Position: 1 56 | Default value: 57 | Accept pipeline input: True (ByValue) 58 | Accept wildcard characters: False 59 | ``` 60 | 61 | ### -DontExpandSingleLineBlocks 62 | Skip expansion of a codeblock if it only has a single line. 63 | 64 | ```yaml 65 | Type: SwitchParameter 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: False 70 | Position: 2 71 | Default value: False 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### -SkipPostProcessingValidityCheck 77 | After modifications have been made a check will be performed that the code has no errors. 78 | Use this switch to bypass this check 79 | (This is not recommended!) 80 | 81 | ```yaml 82 | Type: SwitchParameter 83 | Parameter Sets: (All) 84 | Aliases: 85 | 86 | Required: False 87 | Position: 3 88 | Default value: False 89 | Accept pipeline input: False 90 | Accept wildcard characters: False 91 | ``` 92 | 93 | ## INPUTS 94 | 95 | ## OUTPUTS 96 | 97 | ## NOTES 98 | Author: Zachary Loeber 99 | Site: http://www.the-little-things.net/ 100 | Requires: Powershell 3.0 101 | 102 | Version History 103 | 1.0.0 - Initial release 104 | 105 | ## RELATED LINKS 106 | 107 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 108 | 109 | [http://www.the-little-things.net](http://www.the-little-things.net) 110 | 111 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptExpandTypeAccelerators.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandTypeAccelerators 8 | ## SYNOPSIS 9 | Converts shorthand type accelerators to their full name. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandTypeAccelerators [-Code] [-AllTypes] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Converts shorthand type accelerators to their full name. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptExpandTypeAccelerators -AllTypes | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, converts all type accelerators to their full name and places the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multi-line or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -AllTypes 53 | Include system type accelerators. 54 | 55 | ```yaml 56 | Type: SwitchParameter 57 | Parameter Sets: (All) 58 | Aliases: 59 | 60 | Required: False 61 | Position: 2 62 | Default value: False 63 | Accept pipeline input: False 64 | Accept wildcard characters: False 65 | ``` 66 | 67 | ### -SkipPostProcessingValidityCheck 68 | After modifications have been made a check will be performed that the code has no errors. 69 | Use this switch to bypass this check 70 | (This is not recommended!) 71 | 72 | ```yaml 73 | Type: SwitchParameter 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: 3 79 | Default value: False 80 | Accept pipeline input: False 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ## INPUTS 85 | 86 | ## OUTPUTS 87 | 88 | ## NOTES 89 | Author: Zachary Loeber 90 | Site: http://www.the-little-things.net/ 91 | Requires: Powershell 3.0 92 | 93 | Version History 94 | 1.0.0 - Initial release 95 | 96 | ## RELATED LINKS 97 | 98 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 99 | 100 | [http://www.the-little-things.net](http://www.the-little-things.net) 101 | 102 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptFormatCodeIndentation.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptFormatCodeIndentation 8 | ## SYNOPSIS 9 | Indents code blocks based on their level. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptFormatCodeIndentation [-Code] [[-Depth] ] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Indents code blocks based on their level. 19 | This is usually the last function you will run if using this module to beautify your code. 20 | 21 | ## EXAMPLES 22 | 23 | ### -------------------------- EXAMPLE 1 -------------------------- 24 | ``` 25 | $testfile = 'C:\temp\test.ps1' 26 | ``` 27 | 28 | PS \> $test = Get-Content $testfile -raw 29 | PS \> $test | Format-ScriptFormatCodeIndentation | clip 30 | 31 | Description 32 | ----------- 33 | Takes C:\temp\test.ps1 as input, indents all code and places the result in the clipboard 34 | to be pasted elsewhere for review. 35 | 36 | ## PARAMETERS 37 | 38 | ### -Code 39 | Multi-line or piped lines of code to process. 40 | 41 | ```yaml 42 | Type: String[] 43 | Parameter Sets: (All) 44 | Aliases: 45 | 46 | Required: True 47 | Position: 1 48 | Default value: 49 | Accept pipeline input: True (ByValue) 50 | Accept wildcard characters: False 51 | ``` 52 | 53 | ### -Depth 54 | How many spaces to indent per level. 55 | Default is 4. 56 | 57 | ```yaml 58 | Type: Int32 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: 4 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### -SkipPostProcessingValidityCheck 70 | After modifications have been made a check will be performed that the code has no errors. 71 | Use this switch to bypass this check 72 | (This is not recommended!) 73 | 74 | ```yaml 75 | Type: SwitchParameter 76 | Parameter Sets: (All) 77 | Aliases: 78 | 79 | Required: False 80 | Position: 3 81 | Default value: False 82 | Accept pipeline input: False 83 | Accept wildcard characters: False 84 | ``` 85 | 86 | ## INPUTS 87 | 88 | ## OUTPUTS 89 | 90 | ## NOTES 91 | Author: Zachary Loeber 92 | Site: http://www.the-little-things.net/ 93 | Requires: Powershell 3.0 94 | Modified a little bit from here: http://www.powershellmagazine.com/2013/09/03/pstip-tabify-your-script/ 95 | 96 | Version History 97 | 1.0.0 - Initial release 98 | 99 | ## RELATED LINKS 100 | 101 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 102 | 103 | [http://www.the-little-things.net](http://www.the-little-things.net) 104 | 105 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptFormatCommandNames.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptFormatCommandNames 8 | ## SYNOPSIS 9 | Converts all found commands to proper case (aka. 10 | PascalCased). 11 | 12 | ## SYNTAX 13 | 14 | ``` 15 | Format-ScriptFormatCommandNames [-Code] [-ExpandAliases] [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Converts all found commands to proper case (aka. 20 | PascalCased). 21 | 22 | ## EXAMPLES 23 | 24 | ### -------------------------- EXAMPLE 1 -------------------------- 25 | ``` 26 | $testfile = 'C:\temp\test.ps1' 27 | ``` 28 | 29 | PS \> $test = Get-Content $testfile -raw 30 | PS \> $test | Format-ScriptFormatCommandNames | clip 31 | 32 | Description 33 | ----------- 34 | Takes C:\temp\test.ps1 as input, PascalCase formats any commands found and places the result in the clipboard 35 | to be pasted elsewhere for review. 36 | 37 | ## PARAMETERS 38 | 39 | ### -Code 40 | Multi-line or piped lines of code to process. 41 | 42 | ```yaml 43 | Type: String[] 44 | Parameter Sets: (All) 45 | Aliases: 46 | 47 | Required: True 48 | Position: 1 49 | Default value: 50 | Accept pipeline input: True (ByValue) 51 | Accept wildcard characters: False 52 | ``` 53 | 54 | ### -ExpandAliases 55 | Expand any found aliases. 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### -SkipPostProcessingValidityCheck 70 | After modifications have been made a check will be performed that the code has no errors. 71 | Use this switch to bypass this check 72 | (This is not recommended!) 73 | 74 | ```yaml 75 | Type: SwitchParameter 76 | Parameter Sets: (All) 77 | Aliases: 78 | 79 | Required: False 80 | Position: 3 81 | Default value: False 82 | Accept pipeline input: False 83 | Accept wildcard characters: False 84 | ``` 85 | 86 | ## INPUTS 87 | 88 | ## OUTPUTS 89 | 90 | ## NOTES 91 | Author: Zachary Loeber 92 | Site: http://www.the-little-things.net/ 93 | Requires: Powershell 3.0 94 | 95 | Version History 96 | 1.0.0 - Initial release 97 | 1.0.1 - Fixed improper handling of ? 98 | alias 99 | - Added more verbose output 100 | 101 | ## RELATED LINKS 102 | 103 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 104 | 105 | [http://www.the-little-things.net](http://www.the-little-things.net) 106 | 107 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptFormatTypeNames.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptFormatTypeNames 8 | ## SYNOPSIS 9 | Converts typenames within code to be properly formated. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptFormatTypeNames [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Converts typenames within code to be properly formated 19 | (ie. 20 | \[bool\] becomes \[Bool\] and \[system.string\] becomes \[System.String\]). 21 | 22 | ## EXAMPLES 23 | 24 | ### -------------------------- EXAMPLE 1 -------------------------- 25 | ``` 26 | $testfile = 'C:\temp\test.ps1' 27 | ``` 28 | 29 | PS \> $test = Get-Content $testfile -raw 30 | PS \> $test | Format-ScriptFormatTypeNames | clip 31 | 32 | Description 33 | ----------- 34 | Takes C:\temp\test.ps1 as input, formats any typenames found and places the result in the clipboard 35 | to be pasted elsewhere for review. 36 | 37 | ## PARAMETERS 38 | 39 | ### -Code 40 | Multiline or piped lines of code to process. 41 | 42 | ```yaml 43 | Type: String[] 44 | Parameter Sets: (All) 45 | Aliases: 46 | 47 | Required: True 48 | Position: 1 49 | Default value: 50 | Accept pipeline input: True (ByValue) 51 | Accept wildcard characters: False 52 | ``` 53 | 54 | ### -SkipPostProcessingValidityCheck 55 | After modifications have been made a check will be performed that the code has no errors. 56 | Use this switch to bypass this check 57 | (This is not recommended!) 58 | 59 | ```yaml 60 | Type: SwitchParameter 61 | Parameter Sets: (All) 62 | Aliases: 63 | 64 | Required: False 65 | Position: 2 66 | Default value: False 67 | Accept pipeline input: False 68 | Accept wildcard characters: False 69 | ``` 70 | 71 | ## INPUTS 72 | 73 | ## OUTPUTS 74 | 75 | ## NOTES 76 | Author: Zachary Loeber 77 | Site: http://www.the-little-things.net/ 78 | Requires: Powershell 3.0 79 | 80 | Version History 81 | 1.0.0 - Initial release 82 | 83 | ## RELATED LINKS 84 | 85 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 86 | 87 | [http://www.the-little-things.net](http://www.the-little-things.net) 88 | 89 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptPadExpressions.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptPadExpressions 8 | ## SYNOPSIS 9 | Pads powershell expressions with single spaces. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptPadExpressions [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Pads powershell expressions with single spaces. 19 | Expressions padded include +,-,/,%, and * 20 | 21 | ## EXAMPLES 22 | 23 | ### -------------------------- EXAMPLE 1 -------------------------- 24 | ``` 25 | $testfile = 'C:\temp\test.ps1' 26 | ``` 27 | 28 | PS \> $test = Get-Content $testfile -raw 29 | PS \> $test | Format-ScriptPadExpressions | clip 30 | 31 | Description 32 | ----------- 33 | Takes C:\temp\test.ps1 as input, pads any expressions found with single spaces and places the result in the clipboard 34 | to be pasted elsewhere for review. 35 | 36 | ## PARAMETERS 37 | 38 | ### -Code 39 | Multi-line or piped lines of code to process. 40 | 41 | ```yaml 42 | Type: String[] 43 | Parameter Sets: (All) 44 | Aliases: 45 | 46 | Required: True 47 | Position: 1 48 | Default value: 49 | Accept pipeline input: True (ByValue) 50 | Accept wildcard characters: False 51 | ``` 52 | 53 | ### -SkipPostProcessingValidityCheck 54 | After modifications have been made a check will be performed that the code has no errors. 55 | Use this switch to bypass this check 56 | (This is not recommended!) 57 | 58 | ```yaml 59 | Type: SwitchParameter 60 | Parameter Sets: (All) 61 | Aliases: 62 | 63 | Required: False 64 | Position: 2 65 | Default value: False 66 | Accept pipeline input: False 67 | Accept wildcard characters: False 68 | ``` 69 | 70 | ## INPUTS 71 | 72 | ## OUTPUTS 73 | 74 | ## NOTES 75 | Author: Zachary Loeber 76 | Site: http://www.the-little-things.net/ 77 | Requires: Powershell 3.0 78 | 79 | Version History 80 | 1.0.0 - Initial release 81 | 82 | ## RELATED LINKS 83 | 84 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 85 | 86 | [http://www.the-little-things.net](http://www.the-little-things.net) 87 | 88 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptPadOperators.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptPadOperators 8 | ## SYNOPSIS 9 | Pads powershell assignment operators with single spaces. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptPadOperators [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Pads powershell assignment operators with single spaces. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptPadOperators | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, spaced all assignment operators and puts the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multi-line or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SkipPostProcessingValidityCheck 53 | After modifications have been made a check will be performed that the code has no errors. 54 | Use this switch to bypass this check 55 | (This is not recommended!) 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ## INPUTS 70 | 71 | ## OUTPUTS 72 | 73 | ## NOTES 74 | Author: Zachary Loeber 75 | Site: http://www.the-little-things.net/ 76 | Requires: Powershell 3.0 77 | 78 | Version History 79 | 1.0.0 - Initial release 80 | 81 | ## RELATED LINKS 82 | 83 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 84 | 85 | [http://www.the-little-things.net](http://www.the-little-things.net) 86 | 87 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptReduceLineLength.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptReduceLineLength 8 | ## SYNOPSIS 9 | Attempt to shorten long lines if possible. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptReduceLineLength [-Code] [[-Length] ] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Attempt to shorten long lines if possible. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptReduceLineLength | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, formats as the function defines and places the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multiline or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -Length 53 | Number of characters to shorten long lines to. 54 | Default is 115 characters as this is best practice. 55 | 56 | ```yaml 57 | Type: Int32 58 | Parameter Sets: (All) 59 | Aliases: 60 | 61 | Required: False 62 | Position: 2 63 | Default value: 115 64 | Accept pipeline input: False 65 | Accept wildcard characters: False 66 | ``` 67 | 68 | ### -SkipPostProcessingValidityCheck 69 | After modifications have been made a check will be performed that the code has no errors. 70 | Use this switch to bypass this check 71 | (This is not recommended!) 72 | 73 | ```yaml 74 | Type: SwitchParameter 75 | Parameter Sets: (All) 76 | Aliases: 77 | 78 | Required: False 79 | Position: 3 80 | Default value: False 81 | Accept pipeline input: False 82 | Accept wildcard characters: False 83 | ``` 84 | 85 | ## INPUTS 86 | 87 | ## OUTPUTS 88 | 89 | ## NOTES 90 | Author: Zachary Loeber 91 | Site: http://www.the-little-things.net/ 92 | Requires: Powershell 3.0 93 | 94 | Version History 95 | 1.0.0 - Initial release 96 | 97 | ## RELATED LINKS 98 | 99 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 100 | 101 | [http://www.the-little-things.net](http://www.the-little-things.net) 102 | 103 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptRemoveStatementSeparators.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptRemoveStatementSeparators 8 | ## SYNOPSIS 9 | Finds all statement separators (semicolons) not in for loops and converts them to newlines. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptRemoveStatementSeparators [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Finds all statement separators (semicolons) not in for loops and converts them to newlines. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-RemoveStatementSeparators | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, remove statement separators and puts the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multi-line or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SkipPostProcessingValidityCheck 53 | After modifications have been made a check will be performed that the code has no errors. 54 | Use this switch to bypass this check 55 | (This is not recommended!) 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ## INPUTS 70 | 71 | ## OUTPUTS 72 | 73 | ## NOTES 74 | Author: Zachary Loeber 75 | Site: http://www.the-little-things.net/ 76 | Requires: Powershell 3.0 77 | 78 | Version History 79 | 1.0.0 - Initial release 80 | 81 | ## RELATED LINKS 82 | 83 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 84 | 85 | [http://www.the-little-things.net](http://www.the-little-things.net) 86 | 87 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptRemoveSuperfluousSpaces.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptRemoveSuperfluousSpaces 8 | ## SYNOPSIS 9 | Removes superfluous spaces at the end of individual lines of code. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptRemoveSuperfluousSpaces [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Removes superfluous spaces at the end of individual lines of code. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | $test = Get-Content $testfile -raw 28 | $test | Format-ScriptRemoveSuperfluousSpaces | Clip 29 | 30 | Description 31 | ----------- 32 | Removes all additional spaces and whitespace from the end of every non-herestring/comment in C:\temp\test.ps1 33 | 34 | ## PARAMETERS 35 | 36 | ### -Code 37 | Multiple lines of code to analyze. 38 | Ignores all herestrings. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SkipPostProcessingValidityCheck 53 | After modifications have been made a check will be performed that the code has no errors. 54 | Use this switch to bypass this check 55 | (This is not recommended!) 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ## INPUTS 70 | 71 | ## OUTPUTS 72 | 73 | ## NOTES 74 | Author: Zachary Loeber 75 | Site: http://www.the-little-things.net/ 76 | 77 | 1.0.0 - Initial release 78 | 79 | ## RELATED LINKS 80 | 81 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 82 | 83 | [http://www.the-little-things.net](http://www.the-little-things.net) 84 | 85 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptReplaceHereStrings.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptReplaceHereStrings 8 | ## SYNOPSIS 9 | Replace here strings with variable created equivalents. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptReplaceHereStrings [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Replace here strings with variable created equivalents. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptReplaceHereStrings | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, formats as the function defines and places the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multiple lines of code to analyze 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SkipPostProcessingValidityCheck 53 | After modifications have been made a check will be performed that the code has no errors. 54 | Use this switch to bypass this check 55 | (This is not recommended!) 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ## INPUTS 70 | 71 | ## OUTPUTS 72 | 73 | ## NOTES 74 | Author: Zachary Loeber 75 | Site: http://www.the-little-things.net/ 76 | Requires: Powershell 3.0 77 | 78 | Version History 79 | 1.0.0 - Initial release 80 | 1.0.1 - Fixed some replacements based on if the string is expandable or not. 81 | - Changed output to be all one assignment rather than multiple assignments 82 | 83 | ## RELATED LINKS 84 | 85 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 86 | 87 | [http://www.the-little-things.net](http://www.the-little-things.net) 88 | 89 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptReplaceInvalidCharacters.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptReplaceInvalidCharacters 8 | ## SYNOPSIS 9 | Find and replaces invalid characters. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptReplaceInvalidCharacters [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Find and replaces invalid characters. 19 | These are often picked up from copying directly from blogging platforms. 20 | Although the scripts seem to 21 | run without issue most of the time they still look different enough to me to be irritating. 22 | So the following characters are replaced if they are not in a here string or comment: 23 | " becomes " 24 | " becomes " 25 | ' becomes ' (This is NOT the same as the line continuation character, the backtick, even if it looks the same in many editors) 26 | ' becomes ' 27 | 28 | ## EXAMPLES 29 | 30 | ### -------------------------- EXAMPLE 1 -------------------------- 31 | ``` 32 | $testfile = 'C:\temp\test.ps1' 33 | ``` 34 | 35 | PS \> $test = Get-Content $testfile -raw 36 | PS \> $test | Format-ScriptReplaceInvalidCharacters 37 | 38 | Description 39 | ----------- 40 | Takes C:\temp\test.ps1 as input, replaces invalid characters and places the result in the console window. 41 | 42 | ## PARAMETERS 43 | 44 | ### -Code 45 | Multiline or piped lines of code to process. 46 | 47 | ```yaml 48 | Type: String[] 49 | Parameter Sets: (All) 50 | Aliases: 51 | 52 | Required: True 53 | Position: 1 54 | Default value: 55 | Accept pipeline input: True (ByValue) 56 | Accept wildcard characters: False 57 | ``` 58 | 59 | ### -SkipPostProcessingValidityCheck 60 | After modifications have been made a check will be performed that the code has no errors. 61 | Use this switch to bypass this check 62 | (This is not recommended!) 63 | 64 | ```yaml 65 | Type: SwitchParameter 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: False 70 | Position: 2 71 | Default value: False 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ## INPUTS 77 | 78 | ## OUTPUTS 79 | 80 | ## NOTES 81 | Author: Zachary Loeber 82 | Site: http://www.the-little-things.net/ 83 | Requires: Powershell 3.0 84 | 85 | Version History 86 | 1.0.0 - Initial release 87 | 88 | ## RELATED LINKS 89 | 90 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 91 | 92 | [http://www.the-little-things.net](http://www.the-little-things.net) 93 | 94 | -------------------------------------------------------------------------------- /release/1.4.1/docs/Format-ScriptTestCodeBlock.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptTestCodeBlock 8 | ## SYNOPSIS 9 | Validates there are no script parsing errors in a script. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptTestCodeBlock [-Code] [-ShowParsingErrors] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Validates there are no script parsing errors in a script. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptTestCodeBlock 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input and validates if the code is valid or not. 33 | Returns $true if it is, $false if it is not. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multiline or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -ShowParsingErrors 53 | Display parsing errors if found. 54 | 55 | ```yaml 56 | Type: SwitchParameter 57 | Parameter Sets: (All) 58 | Aliases: 59 | 60 | Required: False 61 | Position: 2 62 | Default value: False 63 | Accept pipeline input: False 64 | Accept wildcard characters: False 65 | ``` 66 | 67 | ## INPUTS 68 | 69 | ## OUTPUTS 70 | 71 | ## NOTES 72 | Author: Zachary Loeber 73 | Site: http://www.the-little-things.net/ 74 | Requires: Powershell 3.0 75 | 76 | Version History 77 | 1.0.0 - Initial release 78 | 79 | ## RELATED LINKS 80 | 81 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 82 | 83 | [http://www.the-little-things.net](http://www.the-little-things.net) 84 | 85 | -------------------------------------------------------------------------------- /release/1.4.1/docs/FormatPowershellCode.md: -------------------------------------------------------------------------------- 1 | --- 2 | Module Name: FormatPowershellCode 3 | Module Guid: dcfbce3c-18be-4775-b98d-4431d4fb9e08 4 | Download Help Link: https://github.com/zloeber/FormatPowershellCode/release/FormatPowershellCode/docs/FormatPowershellCode.md 5 | Help Version: 1.4.1 6 | Locale: en-US 7 | --- 8 | 9 | # FormatPowershellCode Module 10 | ## Description 11 | A set of functions for standardizing and reformatting PowerShell script code. 12 | 13 | ## FormatPowershellCode Cmdlets 14 | ### [Format-ScriptCondenseEnclosures](Format-ScriptCondenseEnclosures.md) 15 | Moves specified beginning enclosure types to the end of the prior line if found to be on its own line. 16 | 17 | ### [Format-ScriptExpandFunctionBlocks](Format-ScriptExpandFunctionBlocks.md) 18 | Expand any function code blocks found in curly braces from inline to a more readable format. 19 | 20 | ### [Format-ScriptExpandNamedBlocks](Format-ScriptExpandNamedBlocks.md) 21 | Expand any named code blocks found in curly braces from inline to a more readable format. 22 | 23 | ### [Format-ScriptExpandParameterBlocks](Format-ScriptExpandParameterBlocks.md) 24 | Expand any parameter blocks from inline to a more readable format. 25 | 26 | ### [Format-ScriptExpandStatementBlocks](Format-ScriptExpandStatementBlocks.md) 27 | Expand any statement code blocks found in curly braces from inline to a more readable format. 28 | 29 | ### [Format-ScriptExpandTypeAccelerators](Format-ScriptExpandTypeAccelerators.md) 30 | Converts shorthand type accelerators to their full name. 31 | 32 | ### [Format-ScriptFormatCodeIndentation](Format-ScriptFormatCodeIndentation.md) 33 | Indents code blocks based on their level. 34 | 35 | ### [Format-ScriptFormatCommandNames](Format-ScriptFormatCommandNames.md) 36 | Converts all found commands to proper case (aka. PascalCased). 37 | 38 | ### [Format-ScriptFormatTypeNames](Format-ScriptFormatTypeNames.md) 39 | Converts typenames within code to be properly formated. 40 | 41 | ### [Format-ScriptPadExpressions](Format-ScriptPadExpressions.md) 42 | Pads powershell expressions with single spaces. 43 | 44 | ### [Format-ScriptPadOperators](Format-ScriptPadOperators.md) 45 | Pads powershell assignment operators with single spaces. 46 | 47 | ### [Format-ScriptReduceLineLength](Format-ScriptReduceLineLength.md) 48 | Attempt to shorten long lines if possible. 49 | 50 | ### [Format-ScriptRemoveStatementSeparators](Format-ScriptRemoveStatementSeparators.md) 51 | Finds all statement separators (semicolons) not in for loops and converts them to newlines. 52 | 53 | ### [Format-ScriptRemoveSuperfluousSpaces](Format-ScriptRemoveSuperfluousSpaces.md) 54 | Removes superfluous spaces at the end of individual lines of code. 55 | 56 | ### [Format-ScriptReplaceHereStrings](Format-ScriptReplaceHereStrings.md) 57 | Replace here strings with variable created equivalents. 58 | 59 | ### [Format-ScriptReplaceInvalidCharacters](Format-ScriptReplaceInvalidCharacters.md) 60 | Find and replaces invalid characters. 61 | 62 | ### [Format-ScriptTestCodeBlock](Format-ScriptTestCodeBlock.md) 63 | Validates there are no script parsing errors in a script. 64 | 65 | 66 | -------------------------------------------------------------------------------- /release/1.4.1/en-US/FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_HelpInfo.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | https://github.com/zloeber/FormatPowershellCode/release/FormatPowershellCode/docs/FormatPowershellCode.md 4 | 5 | 6 | en-US 7 | 1.4.1 8 | 9 | 10 | -------------------------------------------------------------------------------- /release/1.4.1/en-US/FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_en-US_helpcontent.cab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zloeber/FormatPowershellCode/a8b1d2edec3ed074fa464d4f881556c6dc9e784e/release/1.4.1/en-US/FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_en-US_helpcontent.cab -------------------------------------------------------------------------------- /release/1.4.1/en-US/about_FormatPowershellCode.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_FormatPowerShellCode 3 | 4 | SHORT DESCRIPTION 5 | A set of functions for standardizing and reformatting PowerShell script code. 6 | 7 | LONG DESCRIPTION 8 | A set of functions for standardizing and reformatting PowerShell script code. 9 | 10 | EXAMPLES 11 | import-module .\FormatPowershellCode.psm1 12 | get-content .\tests\testcase-codeblockexpansion.ps1 -raw | 13 | Format-ScriptRemoveStatementSeparators | 14 | Format-ScriptExpandFunctionBlocks | 15 | Format-ScriptExpandNamedBlocks | 16 | Format-ScriptExpandParameterBlocks | 17 | Format-ScriptExpandStatementBlocks | 18 | Format-ScriptFormatCodeIndentation | 19 | clip 20 | 21 | KEYWORDS 22 | Code Formatter, PowerShell Style 23 | 24 | SEE ALSO 25 | NA -------------------------------------------------------------------------------- /release/FormatPowershellCode-1.4.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zloeber/FormatPowershellCode/a8b1d2edec3ed074fa464d4f881556c6dc9e784e/release/FormatPowershellCode-1.4.0.zip -------------------------------------------------------------------------------- /release/FormatPowershellCode-1.4.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zloeber/FormatPowershellCode/a8b1d2edec3ed074fa464d4f881556c6dc9e784e/release/FormatPowershellCode-1.4.1.zip -------------------------------------------------------------------------------- /release/FormatPowershellCode-current.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zloeber/FormatPowershellCode/a8b1d2edec3ed074fa464d4f881556c6dc9e784e/release/FormatPowershellCode-current.zip -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptCondenseEnclosures.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptCondenseEnclosures 8 | ## SYNOPSIS 9 | Moves specified beginning enclosure types to the end of the prior line if found to be on its own line. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptCondenseEnclosures [-Code] [[-EnclosureStart] ] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Moves specified beginning enclosure types to the end of the prior line if found to be on its own line. 20 | 21 | ## EXAMPLES 22 | 23 | ### -------------------------- EXAMPLE 1 -------------------------- 24 | ``` 25 | $test = Get-Content -Raw -Path 'C:\testcases\test-pad-operators.ps1' 26 | ``` 27 | 28 | $test | Format-ScriptCondenseEnclosures | clip 29 | 30 | Description 31 | ----------- 32 | Moves all beginning enclosure characters to the prior line if found to be sitting at the beginning of a line. 33 | 34 | ## PARAMETERS 35 | 36 | ### -Code 37 | Multiple lines of code to analyze 38 | 39 | ```yaml 40 | Type: String[] 41 | Parameter Sets: (All) 42 | Aliases: 43 | 44 | Required: True 45 | Position: 1 46 | Default value: 47 | Accept pipeline input: True (ByValue) 48 | Accept wildcard characters: False 49 | ``` 50 | 51 | ### -EnclosureStart 52 | Array of starting enclosure characters to process (default is (, {, @(, and @{) 53 | 54 | ```yaml 55 | Type: String[] 56 | Parameter Sets: (All) 57 | Aliases: 58 | 59 | Required: False 60 | Position: 2 61 | Default value: @('{','(','@{','@(') 62 | Accept pipeline input: False 63 | Accept wildcard characters: False 64 | ``` 65 | 66 | ### -SkipPostProcessingValidityCheck 67 | After modifications have been made a check will be performed that the code has no errors. 68 | Use this switch to bypass this check (This is not recommended!) 69 | 70 | ```yaml 71 | Type: SwitchParameter 72 | Parameter Sets: (All) 73 | Aliases: 74 | 75 | Required: False 76 | Position: 3 77 | Default value: False 78 | Accept pipeline input: False 79 | Accept wildcard characters: False 80 | ``` 81 | 82 | ## INPUTS 83 | 84 | ## OUTPUTS 85 | 86 | ## NOTES 87 | This function fails to 'condense' anything really complex and probably shouldn't even be used... 88 | 89 | Author: Zachary Loeber 90 | Site: http://www.the-little-things.net/ 91 | 92 | 1.0.0 - 01/25/2015 93 | - Initial release 94 | 95 | ## RELATED LINKS 96 | 97 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 98 | 99 | [http://www.the-little-things.net](http://www.the-little-things.net) 100 | 101 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptExpandFunctionBlocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandFunctionBlocks 8 | ## SYNOPSIS 9 | Expand any function code blocks found in curly braces from inline to a more readable format. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandFunctionBlocks [-Code] [-DontExpandSingleLineBlocks] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Expand any function code blocks found in curly braces from inline to a more readable format. 20 | So this: 21 | function testfunction { Write-Output $_ } 22 | 23 | becomes this: 24 | function testfunction 25 | { 26 | Write-Output $_ 27 | } 28 | 29 | ## EXAMPLES 30 | 31 | ### -------------------------- EXAMPLE 1 -------------------------- 32 | ``` 33 | $testfile = 'C:\temp\test.ps1' 34 | ``` 35 | 36 | PS \> $test = Get-Content $testfile -raw 37 | PS \> $test | Format-ScriptExpandFunctionBlocks | clip 38 | 39 | Description 40 | ----------- 41 | Takes C:\temp\test.ps1 as input, expands code blocks and places the result in the clipboard. 42 | 43 | ## PARAMETERS 44 | 45 | ### -Code 46 | Multiline or piped lines of code to process. 47 | 48 | ```yaml 49 | Type: String[] 50 | Parameter Sets: (All) 51 | Aliases: 52 | 53 | Required: True 54 | Position: 1 55 | Default value: 56 | Accept pipeline input: True (ByValue) 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### -DontExpandSingleLineBlocks 61 | Skip expansion of a codeblock if it only has a single line. 62 | 63 | ```yaml 64 | Type: SwitchParameter 65 | Parameter Sets: (All) 66 | Aliases: 67 | 68 | Required: False 69 | Position: 2 70 | Default value: False 71 | Accept pipeline input: False 72 | Accept wildcard characters: False 73 | ``` 74 | 75 | ### -SkipPostProcessingValidityCheck 76 | After modifications have been made a check will be performed that the code has no errors. 77 | Use this switch to bypass this check 78 | (This is not recommended!) 79 | 80 | ```yaml 81 | Type: SwitchParameter 82 | Parameter Sets: (All) 83 | Aliases: 84 | 85 | Required: False 86 | Position: 3 87 | Default value: False 88 | Accept pipeline input: False 89 | Accept wildcard characters: False 90 | ``` 91 | 92 | ## INPUTS 93 | 94 | ## OUTPUTS 95 | 96 | ## NOTES 97 | Author: Zachary Loeber 98 | Site: http://www.the-little-things.net/ 99 | Requires: Powershell 3.0 100 | 101 | Version History 102 | 1.0.0 - Initial release 103 | 1.0.1 - Fixed awful bug that spit out code without the function declaration (whoops) 104 | 105 | ## RELATED LINKS 106 | 107 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 108 | 109 | [http://www.the-little-things.net](http://www.the-little-things.net) 110 | 111 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptExpandNamedBlocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandNamedBlocks 8 | ## SYNOPSIS 9 | Expand any named code blocks found in curly braces from inline to a more readable format. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandNamedBlocks [-Code] [-DontExpandSingleLineBlocks] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Expand any named code blocks found in curly braces from inline to a more readable format. 20 | So this: 21 | begin { Write-Output $_ } 22 | 23 | becomes this: 24 | 25 | begin 26 | { 27 | Write-Output $_ 28 | } 29 | 30 | ## EXAMPLES 31 | 32 | ### -------------------------- EXAMPLE 1 -------------------------- 33 | ``` 34 | $testfile = 'C:\temp\test.ps1' 35 | ``` 36 | 37 | PS \> $test = Get-Content $testfile -raw 38 | PS \> $test | Format-ScriptExpandNamedBlocks | clip 39 | 40 | Description 41 | ----------- 42 | Takes C:\temp\test.ps1 as input, expands code blocks and places the result in the clipboard. 43 | 44 | ## PARAMETERS 45 | 46 | ### -Code 47 | Multiline or piped lines of code to process. 48 | 49 | ```yaml 50 | Type: String[] 51 | Parameter Sets: (All) 52 | Aliases: 53 | 54 | Required: True 55 | Position: 1 56 | Default value: 57 | Accept pipeline input: True (ByValue) 58 | Accept wildcard characters: False 59 | ``` 60 | 61 | ### -DontExpandSingleLineBlocks 62 | Skip expansion of a codeblock if it only has a single line. 63 | 64 | ```yaml 65 | Type: SwitchParameter 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: False 70 | Position: 2 71 | Default value: False 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### -SkipPostProcessingValidityCheck 77 | After modifications have been made a check will be performed that the code has no errors. 78 | Use this switch to bypass this check 79 | (This is not recommended!) 80 | 81 | ```yaml 82 | Type: SwitchParameter 83 | Parameter Sets: (All) 84 | Aliases: 85 | 86 | Required: False 87 | Position: 3 88 | Default value: False 89 | Accept pipeline input: False 90 | Accept wildcard characters: False 91 | ``` 92 | 93 | ## INPUTS 94 | 95 | ## OUTPUTS 96 | 97 | ## NOTES 98 | Author: Zachary Loeber 99 | Site: http://www.the-little-things.net/ 100 | Requires: Powershell 3.0 101 | 102 | Version History 103 | 1.0.0 - Initial release 104 | 105 | ## RELATED LINKS 106 | 107 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 108 | 109 | [http://www.the-little-things.net](http://www.the-little-things.net) 110 | 111 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptExpandParameterBlocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandParameterBlocks 8 | ## SYNOPSIS 9 | Expand any parameter blocks from inline to a more readable format. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandParameterBlocks [-Code] [-SplitParameterTypeNames] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Expand any parameter blocks from inline to a more readable format. 20 | 21 | ## EXAMPLES 22 | 23 | ### -------------------------- EXAMPLE 1 -------------------------- 24 | ``` 25 | $testfile = 'C:\temp\test.ps1' 26 | ``` 27 | 28 | PS \> $test = Get-Content $testfile -raw 29 | PS \> $test | Format-ScriptExpandParameterBlocks | clip 30 | 31 | Description 32 | ----------- 33 | Takes C:\temp\test.ps1 as input, expands parameter blocks and places the result in the clipboard. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multiline or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SplitParameterTypeNames 53 | Place Parameter typenames on their own line. 54 | 55 | ```yaml 56 | Type: SwitchParameter 57 | Parameter Sets: (All) 58 | Aliases: 59 | 60 | Required: False 61 | Position: 2 62 | Default value: False 63 | Accept pipeline input: False 64 | Accept wildcard characters: False 65 | ``` 66 | 67 | ### -SkipPostProcessingValidityCheck 68 | After modifications have been made a check will be performed that the code has no errors. 69 | Use this switch to bypass this check 70 | (This is not recommended!) 71 | 72 | ```yaml 73 | Type: SwitchParameter 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: 3 79 | Default value: False 80 | Accept pipeline input: False 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ## INPUTS 85 | 86 | ## OUTPUTS 87 | 88 | ## NOTES 89 | Author: Zachary Loeber 90 | Site: http://www.the-little-things.net/ 91 | Requires: Powershell 3.0 92 | 93 | Version History 94 | 1.0.0 - Initial release 95 | 1.0.1 - fixed logic for embedded parameter blocks, added more verbose output. 96 | 1.0.1 - Fixed instance where parameter types were being shortened. 97 | 98 | ## RELATED LINKS 99 | 100 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 101 | 102 | [http://www.the-little-things.net](http://www.the-little-things.net) 103 | 104 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptExpandStatementBlocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandStatementBlocks 8 | ## SYNOPSIS 9 | Expand any statement code blocks found in curly braces from inline to a more readable format. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandStatementBlocks [-Code] [-DontExpandSingleLineBlocks] 15 | [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Expand any statement code blocks found in curly braces from inline to a more readable format. 20 | So this: 21 | if ($a) { Write-Output $true } 22 | 23 | becomes this: 24 | 25 | if ($a) 26 | { 27 | Write-Output $true 28 | } 29 | 30 | ## EXAMPLES 31 | 32 | ### -------------------------- EXAMPLE 1 -------------------------- 33 | ``` 34 | $testfile = 'C:\temp\test.ps1' 35 | ``` 36 | 37 | PS \> $test = Get-Content $testfile -raw 38 | PS \> $test | Format-ScriptExpandStatementBlocks | clip 39 | 40 | Description 41 | ----------- 42 | Takes C:\temp\test.ps1 as input, expands code blocks and places the result in the clipboard. 43 | 44 | ## PARAMETERS 45 | 46 | ### -Code 47 | Multiline or piped lines of code to process. 48 | 49 | ```yaml 50 | Type: String[] 51 | Parameter Sets: (All) 52 | Aliases: 53 | 54 | Required: True 55 | Position: 1 56 | Default value: 57 | Accept pipeline input: True (ByValue) 58 | Accept wildcard characters: False 59 | ``` 60 | 61 | ### -DontExpandSingleLineBlocks 62 | Skip expansion of a codeblock if it only has a single line. 63 | 64 | ```yaml 65 | Type: SwitchParameter 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: False 70 | Position: 2 71 | Default value: False 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### -SkipPostProcessingValidityCheck 77 | After modifications have been made a check will be performed that the code has no errors. 78 | Use this switch to bypass this check 79 | (This is not recommended!) 80 | 81 | ```yaml 82 | Type: SwitchParameter 83 | Parameter Sets: (All) 84 | Aliases: 85 | 86 | Required: False 87 | Position: 3 88 | Default value: False 89 | Accept pipeline input: False 90 | Accept wildcard characters: False 91 | ``` 92 | 93 | ## INPUTS 94 | 95 | ## OUTPUTS 96 | 97 | ## NOTES 98 | Author: Zachary Loeber 99 | Site: http://www.the-little-things.net/ 100 | Requires: Powershell 3.0 101 | 102 | Version History 103 | 1.0.0 - Initial release 104 | 105 | ## RELATED LINKS 106 | 107 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 108 | 109 | [http://www.the-little-things.net](http://www.the-little-things.net) 110 | 111 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptExpandTypeAccelerators.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptExpandTypeAccelerators 8 | ## SYNOPSIS 9 | Converts shorthand type accelerators to their full name. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptExpandTypeAccelerators [-Code] [-AllTypes] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Converts shorthand type accelerators to their full name. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptExpandTypeAccelerators -AllTypes | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, converts all type accelerators to their full name and places the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multi-line or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -AllTypes 53 | Include system type accelerators. 54 | 55 | ```yaml 56 | Type: SwitchParameter 57 | Parameter Sets: (All) 58 | Aliases: 59 | 60 | Required: False 61 | Position: 2 62 | Default value: False 63 | Accept pipeline input: False 64 | Accept wildcard characters: False 65 | ``` 66 | 67 | ### -SkipPostProcessingValidityCheck 68 | After modifications have been made a check will be performed that the code has no errors. 69 | Use this switch to bypass this check 70 | (This is not recommended!) 71 | 72 | ```yaml 73 | Type: SwitchParameter 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: 3 79 | Default value: False 80 | Accept pipeline input: False 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ## INPUTS 85 | 86 | ## OUTPUTS 87 | 88 | ## NOTES 89 | Author: Zachary Loeber 90 | Site: http://www.the-little-things.net/ 91 | Requires: Powershell 3.0 92 | 93 | Version History 94 | 1.0.0 - Initial release 95 | 96 | ## RELATED LINKS 97 | 98 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 99 | 100 | [http://www.the-little-things.net](http://www.the-little-things.net) 101 | 102 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptFormatCodeIndentation.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptFormatCodeIndentation 8 | ## SYNOPSIS 9 | Indents code blocks based on their level. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptFormatCodeIndentation [-Code] [[-Depth] ] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Indents code blocks based on their level. 19 | This is usually the last function you will run if using this module to beautify your code. 20 | 21 | ## EXAMPLES 22 | 23 | ### -------------------------- EXAMPLE 1 -------------------------- 24 | ``` 25 | $testfile = 'C:\temp\test.ps1' 26 | ``` 27 | 28 | PS \> $test = Get-Content $testfile -raw 29 | PS \> $test | Format-ScriptFormatCodeIndentation | clip 30 | 31 | Description 32 | ----------- 33 | Takes C:\temp\test.ps1 as input, indents all code and places the result in the clipboard 34 | to be pasted elsewhere for review. 35 | 36 | ## PARAMETERS 37 | 38 | ### -Code 39 | Multi-line or piped lines of code to process. 40 | 41 | ```yaml 42 | Type: String[] 43 | Parameter Sets: (All) 44 | Aliases: 45 | 46 | Required: True 47 | Position: 1 48 | Default value: 49 | Accept pipeline input: True (ByValue) 50 | Accept wildcard characters: False 51 | ``` 52 | 53 | ### -Depth 54 | How many spaces to indent per level. 55 | Default is 4. 56 | 57 | ```yaml 58 | Type: Int32 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: 4 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### -SkipPostProcessingValidityCheck 70 | After modifications have been made a check will be performed that the code has no errors. 71 | Use this switch to bypass this check 72 | (This is not recommended!) 73 | 74 | ```yaml 75 | Type: SwitchParameter 76 | Parameter Sets: (All) 77 | Aliases: 78 | 79 | Required: False 80 | Position: 3 81 | Default value: False 82 | Accept pipeline input: False 83 | Accept wildcard characters: False 84 | ``` 85 | 86 | ## INPUTS 87 | 88 | ## OUTPUTS 89 | 90 | ## NOTES 91 | Author: Zachary Loeber 92 | Site: http://www.the-little-things.net/ 93 | Requires: Powershell 3.0 94 | Modified a little bit from here: http://www.powershellmagazine.com/2013/09/03/pstip-tabify-your-script/ 95 | 96 | Version History 97 | 1.0.0 - Initial release 98 | 99 | ## RELATED LINKS 100 | 101 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 102 | 103 | [http://www.the-little-things.net](http://www.the-little-things.net) 104 | 105 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptFormatCommandNames.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptFormatCommandNames 8 | ## SYNOPSIS 9 | Converts all found commands to proper case (aka. 10 | PascalCased). 11 | 12 | ## SYNTAX 13 | 14 | ``` 15 | Format-ScriptFormatCommandNames [-Code] [-ExpandAliases] [-SkipPostProcessingValidityCheck] 16 | ``` 17 | 18 | ## DESCRIPTION 19 | Converts all found commands to proper case (aka. 20 | PascalCased). 21 | 22 | ## EXAMPLES 23 | 24 | ### -------------------------- EXAMPLE 1 -------------------------- 25 | ``` 26 | $testfile = 'C:\temp\test.ps1' 27 | ``` 28 | 29 | PS \> $test = Get-Content $testfile -raw 30 | PS \> $test | Format-ScriptFormatCommandNames | clip 31 | 32 | Description 33 | ----------- 34 | Takes C:\temp\test.ps1 as input, PascalCase formats any commands found and places the result in the clipboard 35 | to be pasted elsewhere for review. 36 | 37 | ## PARAMETERS 38 | 39 | ### -Code 40 | Multi-line or piped lines of code to process. 41 | 42 | ```yaml 43 | Type: String[] 44 | Parameter Sets: (All) 45 | Aliases: 46 | 47 | Required: True 48 | Position: 1 49 | Default value: 50 | Accept pipeline input: True (ByValue) 51 | Accept wildcard characters: False 52 | ``` 53 | 54 | ### -ExpandAliases 55 | Expand any found aliases. 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### -SkipPostProcessingValidityCheck 70 | After modifications have been made a check will be performed that the code has no errors. 71 | Use this switch to bypass this check 72 | (This is not recommended!) 73 | 74 | ```yaml 75 | Type: SwitchParameter 76 | Parameter Sets: (All) 77 | Aliases: 78 | 79 | Required: False 80 | Position: 3 81 | Default value: False 82 | Accept pipeline input: False 83 | Accept wildcard characters: False 84 | ``` 85 | 86 | ## INPUTS 87 | 88 | ## OUTPUTS 89 | 90 | ## NOTES 91 | Author: Zachary Loeber 92 | Site: http://www.the-little-things.net/ 93 | Requires: Powershell 3.0 94 | 95 | Version History 96 | 1.0.0 - Initial release 97 | 1.0.1 - Fixed improper handling of ? 98 | alias 99 | - Added more verbose output 100 | 101 | ## RELATED LINKS 102 | 103 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 104 | 105 | [http://www.the-little-things.net](http://www.the-little-things.net) 106 | 107 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptFormatTypeNames.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptFormatTypeNames 8 | ## SYNOPSIS 9 | Converts typenames within code to be properly formated. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptFormatTypeNames [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Converts typenames within code to be properly formated 19 | (ie. 20 | \[bool\] becomes \[Bool\] and \[system.string\] becomes \[System.String\]). 21 | 22 | ## EXAMPLES 23 | 24 | ### -------------------------- EXAMPLE 1 -------------------------- 25 | ``` 26 | $testfile = 'C:\temp\test.ps1' 27 | ``` 28 | 29 | PS \> $test = Get-Content $testfile -raw 30 | PS \> $test | Format-ScriptFormatTypeNames | clip 31 | 32 | Description 33 | ----------- 34 | Takes C:\temp\test.ps1 as input, formats any typenames found and places the result in the clipboard 35 | to be pasted elsewhere for review. 36 | 37 | ## PARAMETERS 38 | 39 | ### -Code 40 | Multiline or piped lines of code to process. 41 | 42 | ```yaml 43 | Type: String[] 44 | Parameter Sets: (All) 45 | Aliases: 46 | 47 | Required: True 48 | Position: 1 49 | Default value: 50 | Accept pipeline input: True (ByValue) 51 | Accept wildcard characters: False 52 | ``` 53 | 54 | ### -SkipPostProcessingValidityCheck 55 | After modifications have been made a check will be performed that the code has no errors. 56 | Use this switch to bypass this check 57 | (This is not recommended!) 58 | 59 | ```yaml 60 | Type: SwitchParameter 61 | Parameter Sets: (All) 62 | Aliases: 63 | 64 | Required: False 65 | Position: 2 66 | Default value: False 67 | Accept pipeline input: False 68 | Accept wildcard characters: False 69 | ``` 70 | 71 | ## INPUTS 72 | 73 | ## OUTPUTS 74 | 75 | ## NOTES 76 | Author: Zachary Loeber 77 | Site: http://www.the-little-things.net/ 78 | Requires: Powershell 3.0 79 | 80 | Version History 81 | 1.0.0 - Initial release 82 | 83 | ## RELATED LINKS 84 | 85 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 86 | 87 | [http://www.the-little-things.net](http://www.the-little-things.net) 88 | 89 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptPadExpressions.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptPadExpressions 8 | ## SYNOPSIS 9 | Pads powershell expressions with single spaces. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptPadExpressions [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Pads powershell expressions with single spaces. 19 | Expressions padded include +,-,/,%, and * 20 | 21 | ## EXAMPLES 22 | 23 | ### -------------------------- EXAMPLE 1 -------------------------- 24 | ``` 25 | $testfile = 'C:\temp\test.ps1' 26 | ``` 27 | 28 | PS \> $test = Get-Content $testfile -raw 29 | PS \> $test | Format-ScriptPadExpressions | clip 30 | 31 | Description 32 | ----------- 33 | Takes C:\temp\test.ps1 as input, pads any expressions found with single spaces and places the result in the clipboard 34 | to be pasted elsewhere for review. 35 | 36 | ## PARAMETERS 37 | 38 | ### -Code 39 | Multi-line or piped lines of code to process. 40 | 41 | ```yaml 42 | Type: String[] 43 | Parameter Sets: (All) 44 | Aliases: 45 | 46 | Required: True 47 | Position: 1 48 | Default value: 49 | Accept pipeline input: True (ByValue) 50 | Accept wildcard characters: False 51 | ``` 52 | 53 | ### -SkipPostProcessingValidityCheck 54 | After modifications have been made a check will be performed that the code has no errors. 55 | Use this switch to bypass this check 56 | (This is not recommended!) 57 | 58 | ```yaml 59 | Type: SwitchParameter 60 | Parameter Sets: (All) 61 | Aliases: 62 | 63 | Required: False 64 | Position: 2 65 | Default value: False 66 | Accept pipeline input: False 67 | Accept wildcard characters: False 68 | ``` 69 | 70 | ## INPUTS 71 | 72 | ## OUTPUTS 73 | 74 | ## NOTES 75 | Author: Zachary Loeber 76 | Site: http://www.the-little-things.net/ 77 | Requires: Powershell 3.0 78 | 79 | Version History 80 | 1.0.0 - Initial release 81 | 82 | ## RELATED LINKS 83 | 84 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 85 | 86 | [http://www.the-little-things.net](http://www.the-little-things.net) 87 | 88 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptPadOperators.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptPadOperators 8 | ## SYNOPSIS 9 | Pads powershell assignment operators with single spaces. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptPadOperators [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Pads powershell assignment operators with single spaces. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptPadOperators | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, spaced all assignment operators and puts the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multi-line or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SkipPostProcessingValidityCheck 53 | After modifications have been made a check will be performed that the code has no errors. 54 | Use this switch to bypass this check 55 | (This is not recommended!) 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ## INPUTS 70 | 71 | ## OUTPUTS 72 | 73 | ## NOTES 74 | Author: Zachary Loeber 75 | Site: http://www.the-little-things.net/ 76 | Requires: Powershell 3.0 77 | 78 | Version History 79 | 1.0.0 - Initial release 80 | 81 | ## RELATED LINKS 82 | 83 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 84 | 85 | [http://www.the-little-things.net](http://www.the-little-things.net) 86 | 87 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptReduceLineLength.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptReduceLineLength 8 | ## SYNOPSIS 9 | Attempt to shorten long lines if possible. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptReduceLineLength [-Code] [[-Length] ] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Attempt to shorten long lines if possible. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptReduceLineLength | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, formats as the function defines and places the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multiline or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -Length 53 | Number of characters to shorten long lines to. 54 | Default is 115 characters as this is best practice. 55 | 56 | ```yaml 57 | Type: Int32 58 | Parameter Sets: (All) 59 | Aliases: 60 | 61 | Required: False 62 | Position: 2 63 | Default value: 115 64 | Accept pipeline input: False 65 | Accept wildcard characters: False 66 | ``` 67 | 68 | ### -SkipPostProcessingValidityCheck 69 | After modifications have been made a check will be performed that the code has no errors. 70 | Use this switch to bypass this check 71 | (This is not recommended!) 72 | 73 | ```yaml 74 | Type: SwitchParameter 75 | Parameter Sets: (All) 76 | Aliases: 77 | 78 | Required: False 79 | Position: 3 80 | Default value: False 81 | Accept pipeline input: False 82 | Accept wildcard characters: False 83 | ``` 84 | 85 | ## INPUTS 86 | 87 | ## OUTPUTS 88 | 89 | ## NOTES 90 | Author: Zachary Loeber 91 | Site: http://www.the-little-things.net/ 92 | Requires: Powershell 3.0 93 | 94 | Version History 95 | 1.0.0 - Initial release 96 | 97 | ## RELATED LINKS 98 | 99 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 100 | 101 | [http://www.the-little-things.net](http://www.the-little-things.net) 102 | 103 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptRemoveStatementSeparators.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptRemoveStatementSeparators 8 | ## SYNOPSIS 9 | Finds all statement separators (semicolons) not in for loops and converts them to newlines. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptRemoveStatementSeparators [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Finds all statement separators (semicolons) not in for loops and converts them to newlines. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-RemoveStatementSeparators | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, remove statement separators and puts the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multi-line or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SkipPostProcessingValidityCheck 53 | After modifications have been made a check will be performed that the code has no errors. 54 | Use this switch to bypass this check 55 | (This is not recommended!) 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ## INPUTS 70 | 71 | ## OUTPUTS 72 | 73 | ## NOTES 74 | Author: Zachary Loeber 75 | Site: http://www.the-little-things.net/ 76 | Requires: Powershell 3.0 77 | 78 | Version History 79 | 1.0.0 - Initial release 80 | 81 | ## RELATED LINKS 82 | 83 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 84 | 85 | [http://www.the-little-things.net](http://www.the-little-things.net) 86 | 87 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptRemoveSuperfluousSpaces.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptRemoveSuperfluousSpaces 8 | ## SYNOPSIS 9 | Removes superfluous spaces at the end of individual lines of code. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptRemoveSuperfluousSpaces [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Removes superfluous spaces at the end of individual lines of code. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | $test = Get-Content $testfile -raw 28 | $test | Format-ScriptRemoveSuperfluousSpaces | Clip 29 | 30 | Description 31 | ----------- 32 | Removes all additional spaces and whitespace from the end of every non-herestring/comment in C:\temp\test.ps1 33 | 34 | ## PARAMETERS 35 | 36 | ### -Code 37 | Multiple lines of code to analyze. 38 | Ignores all herestrings. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SkipPostProcessingValidityCheck 53 | After modifications have been made a check will be performed that the code has no errors. 54 | Use this switch to bypass this check 55 | (This is not recommended!) 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ## INPUTS 70 | 71 | ## OUTPUTS 72 | 73 | ## NOTES 74 | Author: Zachary Loeber 75 | Site: http://www.the-little-things.net/ 76 | 77 | 1.0.0 - Initial release 78 | 79 | ## RELATED LINKS 80 | 81 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 82 | 83 | [http://www.the-little-things.net](http://www.the-little-things.net) 84 | 85 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptReplaceHereStrings.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptReplaceHereStrings 8 | ## SYNOPSIS 9 | Replace here strings with variable created equivalents. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptReplaceHereStrings [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Replace here strings with variable created equivalents. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptReplaceHereStrings | clip 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input, formats as the function defines and places the result in the clipboard 33 | to be pasted elsewhere for review. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multiple lines of code to analyze 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -SkipPostProcessingValidityCheck 53 | After modifications have been made a check will be performed that the code has no errors. 54 | Use this switch to bypass this check 55 | (This is not recommended!) 56 | 57 | ```yaml 58 | Type: SwitchParameter 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 2 64 | Default value: False 65 | Accept pipeline input: False 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ## INPUTS 70 | 71 | ## OUTPUTS 72 | 73 | ## NOTES 74 | Author: Zachary Loeber 75 | Site: http://www.the-little-things.net/ 76 | Requires: Powershell 3.0 77 | 78 | Version History 79 | 1.0.0 - Initial release 80 | 1.0.1 - Fixed some replacements based on if the string is expandable or not. 81 | - Changed output to be all one assignment rather than multiple assignments 82 | 83 | ## RELATED LINKS 84 | 85 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 86 | 87 | [http://www.the-little-things.net](http://www.the-little-things.net) 88 | 89 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptReplaceInvalidCharacters.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptReplaceInvalidCharacters 8 | ## SYNOPSIS 9 | Find and replaces invalid characters. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptReplaceInvalidCharacters [-Code] [-SkipPostProcessingValidityCheck] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Find and replaces invalid characters. 19 | These are often picked up from copying directly from blogging platforms. 20 | Although the scripts seem to 21 | run without issue most of the time they still look different enough to me to be irritating. 22 | So the following characters are replaced if they are not in a here string or comment: 23 | " becomes " 24 | " becomes " 25 | ' becomes ' (This is NOT the same as the line continuation character, the backtick, even if it looks the same in many editors) 26 | ' becomes ' 27 | 28 | ## EXAMPLES 29 | 30 | ### -------------------------- EXAMPLE 1 -------------------------- 31 | ``` 32 | $testfile = 'C:\temp\test.ps1' 33 | ``` 34 | 35 | PS \> $test = Get-Content $testfile -raw 36 | PS \> $test | Format-ScriptReplaceInvalidCharacters 37 | 38 | Description 39 | ----------- 40 | Takes C:\temp\test.ps1 as input, replaces invalid characters and places the result in the console window. 41 | 42 | ## PARAMETERS 43 | 44 | ### -Code 45 | Multiline or piped lines of code to process. 46 | 47 | ```yaml 48 | Type: String[] 49 | Parameter Sets: (All) 50 | Aliases: 51 | 52 | Required: True 53 | Position: 1 54 | Default value: 55 | Accept pipeline input: True (ByValue) 56 | Accept wildcard characters: False 57 | ``` 58 | 59 | ### -SkipPostProcessingValidityCheck 60 | After modifications have been made a check will be performed that the code has no errors. 61 | Use this switch to bypass this check 62 | (This is not recommended!) 63 | 64 | ```yaml 65 | Type: SwitchParameter 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: False 70 | Position: 2 71 | Default value: False 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ## INPUTS 77 | 78 | ## OUTPUTS 79 | 80 | ## NOTES 81 | Author: Zachary Loeber 82 | Site: http://www.the-little-things.net/ 83 | Requires: Powershell 3.0 84 | 85 | Version History 86 | 1.0.0 - Initial release 87 | 88 | ## RELATED LINKS 89 | 90 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 91 | 92 | [http://www.the-little-things.net](http://www.the-little-things.net) 93 | 94 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/Format-ScriptTestCodeBlock.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: FormatPowerShellCode-help.xml 3 | online version: https://github.com/zloeber/FormatPowershellCode 4 | schema: 2.0.0 5 | --- 6 | 7 | # Format-ScriptTestCodeBlock 8 | ## SYNOPSIS 9 | Validates there are no script parsing errors in a script. 10 | 11 | ## SYNTAX 12 | 13 | ``` 14 | Format-ScriptTestCodeBlock [-Code] [-ShowParsingErrors] 15 | ``` 16 | 17 | ## DESCRIPTION 18 | Validates there are no script parsing errors in a script. 19 | 20 | ## EXAMPLES 21 | 22 | ### -------------------------- EXAMPLE 1 -------------------------- 23 | ``` 24 | $testfile = 'C:\temp\test.ps1' 25 | ``` 26 | 27 | PS \> $test = Get-Content $testfile -raw 28 | PS \> $test | Format-ScriptTestCodeBlock 29 | 30 | Description 31 | ----------- 32 | Takes C:\temp\test.ps1 as input and validates if the code is valid or not. 33 | Returns $true if it is, $false if it is not. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Code 38 | Multiline or piped lines of code to process. 39 | 40 | ```yaml 41 | Type: String[] 42 | Parameter Sets: (All) 43 | Aliases: 44 | 45 | Required: True 46 | Position: 1 47 | Default value: 48 | Accept pipeline input: True (ByValue) 49 | Accept wildcard characters: False 50 | ``` 51 | 52 | ### -ShowParsingErrors 53 | Display parsing errors if found. 54 | 55 | ```yaml 56 | Type: SwitchParameter 57 | Parameter Sets: (All) 58 | Aliases: 59 | 60 | Required: False 61 | Position: 2 62 | Default value: False 63 | Accept pipeline input: False 64 | Accept wildcard characters: False 65 | ``` 66 | 67 | ## INPUTS 68 | 69 | ## OUTPUTS 70 | 71 | ## NOTES 72 | Author: Zachary Loeber 73 | Site: http://www.the-little-things.net/ 74 | Requires: Powershell 3.0 75 | 76 | Version History 77 | 1.0.0 - Initial release 78 | 79 | ## RELATED LINKS 80 | 81 | [https://github.com/zloeber/FormatPowershellCode](https://github.com/zloeber/FormatPowershellCode) 82 | 83 | [http://www.the-little-things.net](http://www.the-little-things.net) 84 | 85 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/docs/FormatPowershellCode.md: -------------------------------------------------------------------------------- 1 | --- 2 | Module Name: FormatPowershellCode 3 | Module Guid: dcfbce3c-18be-4775-b98d-4431d4fb9e08 4 | Download Help Link: https://github.com/zloeber/FormatPowershellCode/release/FormatPowershellCode/docs/FormatPowershellCode.md 5 | Help Version: 1.4.1 6 | Locale: en-US 7 | --- 8 | 9 | # FormatPowershellCode Module 10 | ## Description 11 | A set of functions for standardizing and reformatting PowerShell script code. 12 | 13 | ## FormatPowershellCode Cmdlets 14 | ### [Format-ScriptCondenseEnclosures](Format-ScriptCondenseEnclosures.md) 15 | Moves specified beginning enclosure types to the end of the prior line if found to be on its own line. 16 | 17 | ### [Format-ScriptExpandFunctionBlocks](Format-ScriptExpandFunctionBlocks.md) 18 | Expand any function code blocks found in curly braces from inline to a more readable format. 19 | 20 | ### [Format-ScriptExpandNamedBlocks](Format-ScriptExpandNamedBlocks.md) 21 | Expand any named code blocks found in curly braces from inline to a more readable format. 22 | 23 | ### [Format-ScriptExpandParameterBlocks](Format-ScriptExpandParameterBlocks.md) 24 | Expand any parameter blocks from inline to a more readable format. 25 | 26 | ### [Format-ScriptExpandStatementBlocks](Format-ScriptExpandStatementBlocks.md) 27 | Expand any statement code blocks found in curly braces from inline to a more readable format. 28 | 29 | ### [Format-ScriptExpandTypeAccelerators](Format-ScriptExpandTypeAccelerators.md) 30 | Converts shorthand type accelerators to their full name. 31 | 32 | ### [Format-ScriptFormatCodeIndentation](Format-ScriptFormatCodeIndentation.md) 33 | Indents code blocks based on their level. 34 | 35 | ### [Format-ScriptFormatCommandNames](Format-ScriptFormatCommandNames.md) 36 | Converts all found commands to proper case (aka. PascalCased). 37 | 38 | ### [Format-ScriptFormatTypeNames](Format-ScriptFormatTypeNames.md) 39 | Converts typenames within code to be properly formated. 40 | 41 | ### [Format-ScriptPadExpressions](Format-ScriptPadExpressions.md) 42 | Pads powershell expressions with single spaces. 43 | 44 | ### [Format-ScriptPadOperators](Format-ScriptPadOperators.md) 45 | Pads powershell assignment operators with single spaces. 46 | 47 | ### [Format-ScriptReduceLineLength](Format-ScriptReduceLineLength.md) 48 | Attempt to shorten long lines if possible. 49 | 50 | ### [Format-ScriptRemoveStatementSeparators](Format-ScriptRemoveStatementSeparators.md) 51 | Finds all statement separators (semicolons) not in for loops and converts them to newlines. 52 | 53 | ### [Format-ScriptRemoveSuperfluousSpaces](Format-ScriptRemoveSuperfluousSpaces.md) 54 | Removes superfluous spaces at the end of individual lines of code. 55 | 56 | ### [Format-ScriptReplaceHereStrings](Format-ScriptReplaceHereStrings.md) 57 | Replace here strings with variable created equivalents. 58 | 59 | ### [Format-ScriptReplaceInvalidCharacters](Format-ScriptReplaceInvalidCharacters.md) 60 | Find and replaces invalid characters. 61 | 62 | ### [Format-ScriptTestCodeBlock](Format-ScriptTestCodeBlock.md) 63 | Validates there are no script parsing errors in a script. 64 | 65 | 66 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/en-US/FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_HelpInfo.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | https://github.com/zloeber/FormatPowershellCode/release/FormatPowershellCode/docs/FormatPowershellCode.md 4 | 5 | 6 | en-US 7 | 1.4.1 8 | 9 | 10 | -------------------------------------------------------------------------------- /release/FormatPowershellCode/en-US/FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_en-US_helpcontent.cab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zloeber/FormatPowershellCode/a8b1d2edec3ed074fa464d4f881556c6dc9e784e/release/FormatPowershellCode/en-US/FormatPowershellCode_dcfbce3c-18be-4775-b98d-4431d4fb9e08_en-US_helpcontent.cab -------------------------------------------------------------------------------- /release/FormatPowershellCode/en-US/about_FormatPowershellCode.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_FormatPowerShellCode 3 | 4 | SHORT DESCRIPTION 5 | A set of functions for standardizing and reformatting PowerShell script code. 6 | 7 | LONG DESCRIPTION 8 | A set of functions for standardizing and reformatting PowerShell script code. 9 | 10 | EXAMPLES 11 | import-module .\FormatPowershellCode.psm1 12 | get-content .\tests\testcase-codeblockexpansion.ps1 -raw | 13 | Format-ScriptRemoveStatementSeparators | 14 | Format-ScriptExpandFunctionBlocks | 15 | Format-ScriptExpandNamedBlocks | 16 | Format-ScriptExpandParameterBlocks | 17 | Format-ScriptExpandStatementBlocks | 18 | Format-ScriptFormatCodeIndentation | 19 | clip 20 | 21 | KEYWORDS 22 | Code Formatter, PowerShell Style 23 | 24 | SEE ALSO 25 | NA -------------------------------------------------------------------------------- /src/depreciated/Format-ScriptConvertKeywordsAndOperatorsToLower.ps1: -------------------------------------------------------------------------------- 1 | function Format-ScriptConvertKeywordsAndOperatorsToLower { 2 | <# 3 | .SYNOPSIS 4 | Converts powershell keywords and operators to lowercase. 5 | .DESCRIPTION 6 | Converts powershell keywords and operators to lowercase. 7 | .PARAMETER Code 8 | Multiple lines of code to analyze 9 | .EXAMPLE 10 | TBD 11 | 12 | Description 13 | ----------- 14 | TBD 15 | 16 | .NOTES 17 | Author: Zachary Loeber 18 | Site: http://www.the-little-things.net/ 19 | 20 | 1.0.0 - 01/25/2015 21 | - Initial release 22 | #> 23 | [CmdletBinding()] 24 | param( 25 | [parameter(Position=0, ValueFromPipeline=$true, HelpMessage='Lines of code to process.')] 26 | [string[]]$Code 27 | ) 28 | begin { 29 | Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState 30 | $Codeblock = @() 31 | } 32 | process { 33 | $Codeblock += $Code 34 | } 35 | end { 36 | $Codeblock = ($Codeblock | Out-String).Trim() 37 | 38 | $ScriptBlock = [Scriptblock]::Create($Codeblock) 39 | [Management.Automation.PSParser]::Tokenize($ScriptBlock, [ref]$null) | 40 | Where {($_.Type -eq 'keyword') -or ($_.Type -eq 'operator') -and (($_.Content).length -gt 1)} | Foreach { 41 | $Convert = $false 42 | if (($_.Content -match "^-{1}\w{2,}$") -and ($_.Content -cmatch "[A-Z]") -and ($_.Type -eq 'operator') -or 43 | (($_.Type -eq 'keyword') -and ($_.Content -cmatch "[A-Z]"))) { 44 | $Convert = $true 45 | } 46 | if ($Convert) { 47 | Write-Verbose "Convert-KeywordsAndOperatorsToLower: Converted keyword $($_.Content) at line $($_.StartLine)" 48 | $Codeblock = $Codeblock.Remove($_.Start,$_.Length) 49 | $Codeblock = $Codeblock.Insert($_.Start,($_.Content).ToLower()) 50 | } 51 | } 52 | 53 | $Codeblock 54 | } 55 | } -------------------------------------------------------------------------------- /src/depreciated/Format-ScriptExpandAliases.ps1: -------------------------------------------------------------------------------- 1 | function Format-ScriptExpandAliases { 2 | [CmdletBinding()] 3 | param ( 4 | [parameter(Position=0, ValueFromPipeline=$true, HelpMessage='Lines of code to to process.')] 5 | [string[]]$Code 6 | ) 7 | begin { 8 | Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState 9 | [string]$finalstring = '' 10 | } 11 | 12 | process { 13 | $Codeblock += $Code 14 | } 15 | end { 16 | $FullCodeBlock = ($Codeblock | Out-String).Trim() 17 | $ScriptBlock = [Scriptblock]::Create($FullCodeBlock) 18 | $Tokens = [Management.Automation.PSParser]::Tokenize($ScriptBlock, [ref]$null) 19 | $column = 1 20 | foreach ($token in $tokens) { 21 | $newtokenval = '' 22 | $padding = (" " * ($token.StartColumn - $column)) 23 | $column = $token.EndColumn 24 | switch($token.type){ 25 | 'Variable' { 26 | $finalstring = $finalstring + $padding + ('${0}' -f $token.content) 27 | } 28 | # 'Type' { 29 | # $newtokenval = '[{0}]' -f $token.content 30 | # } 31 | 'Command' { 32 | $alias = (get-alias | where {$_.name -eq $token.content}).ResolvedCommandName 33 | if($alias) { 34 | Write-Verbose "Expand-Aliases: Found and expanded alias $($token.content) to $alias!" 35 | $finalstring = $finalstring + $padding + $alias 36 | } 37 | else { 38 | $finalstring = $finalstring + $padding + $token.content 39 | } 40 | } 41 | 'String' { 42 | # If we have single quotes or possible variable name then use double quotes 43 | if ($token.content -match "\'|\$") { 44 | $finalstring = $finalstring + $padding + ('"{0}"' -f $token.content) 45 | } 46 | # Otherwise use single quotes 47 | else { 48 | $finalstring = $finalstring + $padding + ("'{0}'" -f $token.content) 49 | } 50 | } 51 | default { 52 | $finalstring = $finalstring + $padding + $token.content 53 | } 54 | } 55 | } 56 | 57 | $finalstring 58 | } 59 | } -------------------------------------------------------------------------------- /src/depreciated/Format-ScriptRemoveStatementSeparatorsOld.ps1: -------------------------------------------------------------------------------- 1 | function Format-ScriptRemoveStatementSeparators { 2 | <# 3 | .SYNOPSIS 4 | Removes superfluous semicolons at the end of individual lines of code and splits them into their own lines of code. 5 | .DESCRIPTION 6 | Removes superfluous semicolons at the end of individual lines of code and splits them into their own lines of code. 7 | .PARAMETER Code 8 | Multiple lines of code to process 9 | 10 | .EXAMPLE 11 | TBD 12 | 13 | Description 14 | ----------- 15 | TBD 16 | 17 | .NOTES 18 | Author: Zachary Loeber 19 | Site: http://www.the-little-things.net/ 20 | 21 | 1.0.0 - 01/25/2015 22 | - Initial release 23 | #> 24 | [CmdletBinding()] 25 | param( 26 | [parameter(Position=0, ValueFromPipeline=$true, HelpMessage='Lines of code to process.')] 27 | [string[]]$Code 28 | ) 29 | begin { 30 | Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState 31 | } 32 | process { 33 | foreach ($codeline in ($Code -split "`r`n")) { 34 | $codeline = $codeline | Remove-SuperfluousSpaces 35 | $count = 0 36 | if ((($codeline -split ';').count -gt 1) -and ($codeline -notmatch '^.*for.*\(.*;.*\).*$')) { 37 | $codeline -split ';' | Foreach { 38 | $_.Trim() 39 | } | foreach { 40 | if ($count -eq 0) { 41 | $outline = $_ 42 | } 43 | else { 44 | if ($_ -match '^#.*') { 45 | $outline += ' ' + $_ 46 | $outline 47 | $outline = '' 48 | } 49 | else { 50 | $outline 51 | $outline = $_ 52 | } 53 | } 54 | $count++ 55 | } 56 | if ($outline -ne '') {$outline} 57 | } 58 | else { 59 | $codeline 60 | } 61 | 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /src/other/1_globals.ps1: -------------------------------------------------------------------------------- 1 | #region Private Variables 2 | # Current script path 3 | [string]$ScriptPath = Split-Path (get-variable myinvocation -scope script).value.Mycommand.Definition -Parent 4 | [bool]$ThisModuleLoaded = $true 5 | #endregion Private Variables 6 | 7 | #region Module Cleanup 8 | $ExecutionContext.SessionState.Module.OnRemove = { 9 | # cleanup when unloading module (if any) 10 | } 11 | #endregion Module Cleanup -------------------------------------------------------------------------------- /src/private/Format-ScriptGetKindLines.ps1: -------------------------------------------------------------------------------- 1 | function Format-ScriptGetKindLines { 2 | <# 3 | .SYNOPSIS 4 | Supplemental function used to get line location of different kinds of AST tokens in a script. 5 | .DESCRIPTION 6 | Supplemental function used to get line location of different kinds of AST tokens in a script. 7 | .PARAMETER Code 8 | Multiline or piped lines of code to process. 9 | .EXAMPLE 10 | PS > $testfile = 'C:\temp\test.ps1' 11 | PS > $test = Get-Content $testfile -raw 12 | PS > $test | Format-ScriptGetKindLines -Kind "HereString*" | clip 13 | 14 | Description 15 | ----------- 16 | Takes C:\temp\test.ps1 as input, formats as the function defines and places the result in the clipboard 17 | to be pasted elsewhere for review. 18 | 19 | .NOTES 20 | Author: Zachary Loeber 21 | Site: http://www.the-little-things.net/ 22 | Requires: Powershell 3.0 23 | 24 | Version History 25 | 1.0.0 - Initial release 26 | #> 27 | [CmdletBinding()] 28 | param( 29 | [parameter(Position=0, ValueFromPipeline=$true, HelpMessage='Lines of code to process.')] 30 | [string[]]$Code, 31 | [parameter(Position=1, HelpMessage='Type of AST kind to retrieve.')] 32 | [string]$Kind = "*" 33 | ) 34 | begin { 35 | $Codeblock = @() 36 | $ParseError = $null 37 | $Tokens = $null 38 | $FunctionName = $MyInvocation.MyCommand.Name 39 | Write-Verbose "$($FunctionName): Begin." 40 | } 41 | process { 42 | $Codeblock += $Code 43 | } 44 | end { 45 | $ScriptText = $Codeblock | Out-String 46 | Write-Verbose "$($FunctionName): Attempting to parse AST." 47 | $AST = [System.Management.Automation.Language.Parser]::ParseInput($ScriptText, [ref]$Tokens, [ref]$ParseError) 48 | 49 | if($ParseError) { 50 | $ParseError | Write-Error 51 | throw "$($FunctionName): Will not work properly with errors in the script, please modify based on the above errors and retry." 52 | } 53 | $TokenKinds = @($Tokens | Where {$_.Kind -like $Kind}) 54 | Foreach ($Token in $TokenKinds) { 55 | New-Object psobject -Property @{ 56 | 'Start' = $Token.Extent.StartLineNumber 57 | 'End' = $Token.Extent.EndLineNumber 58 | } 59 | } 60 | Write-Verbose "$($FunctionName): End." 61 | } 62 | } -------------------------------------------------------------------------------- /src/private/Format-ScriptGetKindLocations.ps1: -------------------------------------------------------------------------------- 1 | function Get-TokenKindLocations { 2 | <# 3 | .SYNOPSIS 4 | Supplemental function used to get exact location of different kinds of AST tokens in a script. 5 | .DESCRIPTION 6 | Supplemental function used to get exact location of different kinds of AST tokens in a script. 7 | .PARAMETER Code 8 | Multiline or piped lines of code to process. 9 | .EXAMPLE 10 | PS > $testfile = 'C:\temp\test.ps1' 11 | PS > $test = Get-Content $testfile -raw 12 | PS > $test | Get-TokenKindLocations -Kind "HereString*" | clip 13 | 14 | Description 15 | ----------- 16 | Takes C:\temp\test.ps1 as input, formats as the function defines and places the result in the clipboard 17 | to be pasted elsewhere for review. 18 | 19 | .NOTES 20 | Author: Zachary Loeber 21 | Site: http://www.the-little-things.net/ 22 | Requires: Powershell 3.0 23 | 24 | Version History 25 | 1.0.0 - Initial release 26 | #> 27 | [CmdletBinding()] 28 | param( 29 | [parameter(Position=0, ValueFromPipeline=$true, HelpMessage='Lines of code to process.')] 30 | [string[]]$Code, 31 | [parameter(Position=1, HelpMessage='Type of AST kind to retrieve.')] 32 | [string[]]$Kind = @() 33 | ) 34 | begin { 35 | $Codeblock = @() 36 | $ParseError = $null 37 | $Tokens = $null 38 | if ($kind.count -gt 0) { 39 | $KindMatch = '^(' + (($Kind | %{[regex]::Escape($_)}) -join '|') + ')$' 40 | } 41 | else { 42 | $KindMatch = '.*' 43 | } 44 | $FunctionName = $MyInvocation.MyCommand.Name 45 | Write-Verbose "$($FunctionName): Begin." 46 | } 47 | process { 48 | $Codeblock += $Code 49 | } 50 | end { 51 | $ScriptText = $Codeblock | Out-String 52 | Write-Verbose "$($FunctionName): Attempting to parse AST." 53 | $AST = [System.Management.Automation.Language.Parser]::ParseInput($ScriptText, [ref]$Tokens, [ref]$ParseError) 54 | 55 | if($ParseError) { 56 | $ParseError | Write-Error 57 | throw "$($FunctionName): Will not work properly with errors in the script, please modify based on the above errors and retry." 58 | } 59 | $TokenKinds = @($Tokens | Where {$_.Kind -match $KindMatch}) 60 | Foreach ($Token in $TokenKinds) { 61 | New-Object psobject -Property @{ 62 | 'Start' = $Token.Extent.StartOffset 63 | 'End' = $Token.Extent.EndOffset 64 | } 65 | } 66 | Write-Verbose "$($FunctionName): End." 67 | } 68 | } -------------------------------------------------------------------------------- /src/private/FormatScript-Definitions.ps1: -------------------------------------------------------------------------------- 1 | # List of token name to string mappings with some unused enums removed 2 | # https://msdn.microsoft.com/en-us/library/system.management.automation.language.tokenkind(v=vs.85).aspx 3 | $TokenKindDefinitions = @{ 4 | 'Ampersand' = '&' 5 | 'And' = '-and' 6 | 'AndAnd' = '&&' 7 | 'As' = '-as' 8 | 'AtCurly' = '@{' 9 | 'AtParen' = '@(' 10 | 'Band' = '-band' 11 | 'Begin' = 'Begin' 12 | 'Bnot' = '-bnot' 13 | 'Bor' = '-bor' 14 | 'Break' = 'break' 15 | 'Bxor' = '-bxor' 16 | 'Catch' = 'catch' 17 | 'Ccontains' = '-ccontains' 18 | 'Ceq' = '-ceq' 19 | 'Cge' = '-cge' 20 | 'Cgt' = '-cgt' 21 | 'Cin' = '-cin' 22 | 'Class' = 'class' 23 | 'Cle' = '-cle' 24 | 'Clike' = '-clike' 25 | 'Clt' = '-clt' 26 | 'Cmatch' = '-cmatch' 27 | 'Cne' = '-cne' 28 | 'Cnotcontains' = '-cnotcontains' 29 | 'Cnotin' = '-cnotin' 30 | 'Cnotlike' = '-cnotlike' 31 | 'Cnotmatch' = '-cnotmatch' 32 | 'ColonColon' = '::' 33 | 'Comma' = ',' 34 | 'Continue' = 'continue' 35 | 'Creplace' = '-creplace' 36 | 'Csplit' = '-csplit' 37 | 'Data' = 'data' 38 | 'Define' = 'define' 39 | 'Divide' = '/' 40 | 'DivideEquals' = '/=' 41 | 'Do' = 'do' 42 | 'DollarParen' = '$(' 43 | 'Dot' = '.' 44 | 'DotDot' = '..' 45 | 'Dynamicparam' = 'dynamicparam' 46 | 'Else' = 'else' 47 | 'ElseIf' = 'elseif' 48 | 'End' = 'end' 49 | 'Enum' = 'enum' 50 | 'Equals' = '=' 51 | 'Exclaim' = '!' 52 | 'Exit' = 'exit' 53 | 'Filter' = 'filter' 54 | 'Finally' = 'finally' 55 | 'For' = 'for' 56 | 'Foreach' = 'foreach' 57 | 'Format' = '-f' 58 | 'From' = 'from' 59 | 'Function' = 'function' 60 | 'Icontains' = '-contains' 61 | 'Ieq' = '-eq' 62 | 'If' = 'if' 63 | 'Ige' = '-ge' 64 | 'Igt' = '-gt' 65 | 'Iin' = '-in' 66 | 'Ile' = '-le' 67 | 'Ilike' = '-like' 68 | 'Ilt' = '-lt' 69 | 'Imatch' = '-match' 70 | 'In' = 'in' 71 | 'Ine' = '-ne' 72 | 'InlineScript' = 'inlinescript' 73 | 'Inotcontains' = '-notcontains' 74 | 'Inotin' = '-notin' 75 | 'Inotlike' = '-notlike' 76 | 'Inotmatch' = '-notmatch' 77 | 'Ireplace' = '-replace' 78 | 'Is' = '-is' 79 | 'IsNot' = '-isnot' 80 | 'Isplit' = '-split' 81 | 'Join' = '-join' 82 | 'LBracket' = '[' 83 | 'LCurly' = '{' 84 | 'LineContinuation' = '`' 85 | 'LParen' = '(' 86 | 'Minus' = '-' 87 | 'MinusEquals' = '-=' 88 | 'MinusMinus' = '--' 89 | 'Multiply' = '*' 90 | 'MultiplyEquals' = '*=' 91 | 'Namespace' = 'namespace' 92 | 'NewLine' = '\r\n' 93 | 'Not' = '-not' 94 | 'Or' = '-or' 95 | 'OrOr' = '||' 96 | 'Parallel' = 'parallel' 97 | 'Param' = 'param' 98 | 'Pipe' = '|' 99 | 'Plus' = '+' 100 | 'PlusEquals' = '+=' 101 | 'PlusPlus' = '++' 102 | 'PostfixMinusMinus' = '--' 103 | 'PostfixPlusPlus' = '++' 104 | 'Private' = 'private' 105 | 'Process' = 'process' 106 | 'Public' = 'public' 107 | 'RBracket' = ']' 108 | 'RCurly' = '}' 109 | 'Rem' = '%' 110 | 'RemainderEquals' = '%=' 111 | 'Return' = 'return' 112 | 'RParen' = ')' 113 | 'Semi' = ';' 114 | 'Sequence' = 'sequence' 115 | 'Shl' = '-shl' 116 | 'Shr' = '-shr' 117 | 'Static' = 'static' 118 | 'Switch' = 'switch' 119 | 'Throw' = 'throw' 120 | 'Trap' = 'trap' 121 | 'Try' = 'try' 122 | 'Type' = 'type' 123 | 'Until' = 'until' 124 | 'While' = 'while' 125 | 'Workflow' = 'workflow' 126 | 'Xor' = '-xor' 127 | } -------------------------------------------------------------------------------- /src/private/Get-BreakableTokens.ps1: -------------------------------------------------------------------------------- 1 | Function Get-BreakableTokens { 2 | [CmdletBinding()] 3 | param( 4 | [parameter(Position=0, ValueFromPipeline=$true, Mandatory=$true, HelpMessage='Tokens to process.')] 5 | [System.Management.Automation.Language.Token[]]$Tokens 6 | ) 7 | begin { 8 | $Kinds = @('Pipe') 9 | # Flags found here: https://msdn.microsoft.com/en-us/library/system.management.automation.language.tokenflags(v=vs.85).aspx 10 | $TokenFlags = @('BinaryPrecedenceAdd','BinaryPrecedenceMultiply','BinaryPrecedenceLogical') 11 | $Kinds_regex = '^(' + (($Kinds | %{[regex]::Escape($_)}) -join '|') + ')$' 12 | $TokenFlags_regex = '(' + (($TokenFlags | %{[regex]::Escape($_)}) -join '|') + ')' 13 | $Results = @() 14 | $AllTokens = @() 15 | } 16 | process { 17 | $AllTokens += $Tokens 18 | } 19 | end { 20 | Foreach ($Token in $AllTokens) { 21 | if (($Token.Kind -match $Kinds_regex) -or ($Token.TokenFlags -match $TokenFlags_regex)) { 22 | $Results += $Token 23 | } 24 | } 25 | $Results 26 | } 27 | } -------------------------------------------------------------------------------- /src/private/Get-NewToken.ps1: -------------------------------------------------------------------------------- 1 | function Get-NewToken { 2 | param($line) 3 | 4 | $results = ( 5 | [System.Management.Automation.PSParser]::Tokenize($line, [ref]$null) # | 6 | # where { 7 | # $_.Type -match 'variable|member|command' -and 8 | # $_.Content -ne "_" 9 | # } 10 | ) 11 | 12 | $results 13 | # $(foreach($result in $results) { ConvertTo-CamelCase $result }) -join '' 14 | } -------------------------------------------------------------------------------- /src/private/Get-ParentASTTypes.ps1: -------------------------------------------------------------------------------- 1 | function Get-ParentASTTypes { 2 | <# 3 | .SYNOPSIS 4 | Retrieves all parent types of a given AST element. 5 | .DESCRIPTION 6 | 7 | .PARAMETER Code 8 | Multiline or piped lines of code to process. 9 | .EXAMPLE 10 | 11 | Description 12 | ----------- 13 | 14 | .NOTES 15 | Author: Zachary Loeber 16 | Site: http://www.the-little-things.net/ 17 | Requires: Powershell 3.0 18 | 19 | Version History 20 | 1.0.0 - Initial release 21 | #> 22 | [CmdletBinding()] 23 | param( 24 | [parameter(Position = 0, Mandatory = $true, ValueFromPipeline=$true, HelpMessage='AST element to process.')] 25 | $AST 26 | ) 27 | # Pull in all the caller verbose,debug,info,warn and other preferences 28 | if ($script:ThisModuleLoaded -eq $true) { Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState } 29 | $FunctionName = $MyInvocation.MyCommand.Name 30 | Write-Verbose "$($FunctionName): Begin." 31 | $ASTParents = @() 32 | if ($AST.Parent -ne $null) { 33 | $CurrentParent = $AST.Parent 34 | $KeepProcessing = $true 35 | } 36 | else { 37 | $KeepProcessing = $false 38 | } 39 | while ($KeepProcessing) { 40 | $ASTParents += $CurrentParent.GetType().Name.ToString() 41 | if ($CurrentParent.Parent -ne $null) { 42 | $CurrentParent = $CurrentParent.Parent 43 | $KeepProcessing = $true 44 | } 45 | else { 46 | $KeepProcessing = $false 47 | } 48 | } 49 | 50 | $ASTParents 51 | Write-Verbose "$($FunctionName): End." 52 | } -------------------------------------------------------------------------------- /src/private/Get-TokenKindLocations.ps1: -------------------------------------------------------------------------------- 1 | function Get-TokenKindLocations { 2 | <# 3 | .SYNOPSIS 4 | Supplemental function used to get exact location of different kinds of AST tokens in a script. 5 | .DESCRIPTION 6 | Supplemental function used to get exact location of different kinds of AST tokens in a script. 7 | .PARAMETER Code 8 | Multiline or piped lines of code to process. 9 | .EXAMPLE 10 | PS > $testfile = 'C:\temp\test.ps1' 11 | PS > $test = Get-Content $testfile -raw 12 | PS > $test | Get-TokenKindLocations -Kind "HereStringLiteral" | clip 13 | 14 | Description 15 | ----------- 16 | Takes C:\temp\test.ps1 as input, formats as the function defines and places the result in the clipboard 17 | to be pasted elsewhere for review. 18 | 19 | .NOTES 20 | Author: Zachary Loeber 21 | Site: http://www.the-little-things.net/ 22 | Requires: Powershell 3.0 23 | 24 | Version History 25 | 1.0.0 - Initial release 26 | #> 27 | [CmdletBinding()] 28 | param( 29 | [parameter(Position=0, ValueFromPipeline=$true, HelpMessage='Lines of code to process.')] 30 | [string[]]$Code, 31 | [parameter(Position=1, HelpMessage='Type of AST kind to retrieve.')] 32 | [string[]]$Kind = @() 33 | ) 34 | begin { 35 | $Codeblock = @() 36 | $ParseError = $null 37 | $Tokens = $null 38 | if ($kind.count -gt 0) { 39 | $KindMatch = '^(' + (($Kind | %{[regex]::Escape($_)}) -join '|') + ')$' 40 | } 41 | else { 42 | $KindMatch = '.*' 43 | } 44 | $FunctionName = $MyInvocation.MyCommand.Name 45 | Write-Verbose "$($FunctionName): Begin." 46 | } 47 | process { 48 | $Codeblock += $Code 49 | } 50 | end { 51 | $ScriptText = $Codeblock | Out-String 52 | Write-Verbose "$($FunctionName): Attempting to parse AST." 53 | $AST = [System.Management.Automation.Language.Parser]::ParseInput($ScriptText, [ref]$Tokens, [ref]$ParseError) 54 | 55 | if($ParseError) { 56 | $ParseError | Write-Error 57 | throw "$($FunctionName): Will not work properly with errors in the script, please modify based on the above errors and retry." 58 | } 59 | $TokenKinds = @($Tokens | Where {$_.Kind -match $KindMatch}) 60 | Foreach ($Token in $TokenKinds) { 61 | New-Object psobject -Property @{ 62 | 'Start' = $Token.Extent.StartOffset 63 | 'End' = $Token.Extent.EndOffset 64 | } 65 | } 66 | Write-Verbose "$($FunctionName): End." 67 | } 68 | } -------------------------------------------------------------------------------- /src/private/Get-TokensBetweenLines.ps1: -------------------------------------------------------------------------------- 1 | function Get-TokensBetweenLines { 2 | <# 3 | .SYNOPSIS 4 | Supplemental function used to get all tokens between the lines requested. 5 | .DESCRIPTION 6 | Supplemental function used to get all tokens between the lines requested. 7 | .PARAMETER Code 8 | Multiline or piped lines of code to process. 9 | .PARAMETER Start 10 | Start line to search 11 | .PARAMETER End 12 | End line to search 13 | .EXAMPLE 14 | PS > $testfile = 'C:\temp\test.ps1' 15 | PS > $test = Get-Content $testfile -raw 16 | PS > $test | Get-TokensBetweenLines -Start 47 -End 47 17 | 18 | Description 19 | ----------- 20 | Takes C:\temp\test.ps1 as input, and returns all tokens on line 47. 21 | 22 | .NOTES 23 | Author: Zachary Loeber 24 | Site: http://www.the-little-things.net/ 25 | Requires: Powershell 3.0 26 | 27 | Version History 28 | 1.0.0 - Initial release 29 | #> 30 | [CmdletBinding()] 31 | param( 32 | [parameter(ValueFromPipeline=$true, HelpMessage='Lines of code to process.')] 33 | [string[]]$Code, 34 | [parameter(Position=1, ValueFromPipeline=$true, Mandatory=$true, HelpMessage='Type of AST kind to retrieve.')] 35 | [int]$Start, 36 | [parameter(Position=2, ValueFromPipeline=$true, Mandatory=$true, HelpMessage='Type of AST kind to retrieve.')] 37 | [int]$End 38 | ) 39 | begin { 40 | $Codeblock = @() 41 | $ParseError = $null 42 | $Tokens = $null 43 | $FunctionName = $MyInvocation.MyCommand.Name 44 | Write-Verbose "$($FunctionName): Begin." 45 | } 46 | process { 47 | $Codeblock += $Code 48 | } 49 | end { 50 | $ScriptText = $Codeblock | Out-String 51 | Write-Verbose "$($FunctionName): Attempting to parse AST." 52 | $AST = [System.Management.Automation.Language.Parser]::ParseInput($ScriptText, [ref]$Tokens, [ref]$ParseError) 53 | 54 | if($ParseError) { 55 | $ParseError | Write-Error 56 | throw "$($FunctionName): Will not work properly with errors in the script, please modify based on the above errors and retry." 57 | } 58 | $Tokens | Where { 59 | ($_.Extent.StartLineNumber -ge $Start) -and 60 | ($_.Extent.EndLineNumber -le $End) 61 | } 62 | Write-Verbose "$($FunctionName): End." 63 | } 64 | } -------------------------------------------------------------------------------- /src/private/Get-TokensOnLineNumber.ps1: -------------------------------------------------------------------------------- 1 | Function Get-TokensOnLineNumber { 2 | [CmdletBinding()] 3 | param( 4 | [parameter(Position=0, ValueFromPipeline=$true, Mandatory=$true, HelpMessage='Tokens to process.')] 5 | [System.Management.Automation.Language.Token[]]$Tokens, 6 | [parameter(Position=1, Mandatory=$true, HelpMessage='Line Number')] 7 | [int]$LineNumber 8 | ) 9 | begin { 10 | $AllTokens = @() 11 | } 12 | process { 13 | $AllTokens += $Tokens 14 | } 15 | end { 16 | $AllTokens | Where {($_.Extent.StartLineNumber -eq $_.Extent.EndLineNumber) -and ($_.Extent.StartLineNumber -eq $LineNumber)} 17 | } 18 | } -------------------------------------------------------------------------------- /src/private/Update-EscapableCharacters.ps1: -------------------------------------------------------------------------------- 1 | function Update-EscapableCharacters { 2 | [CmdletBinding()] 3 | param( 4 | [parameter(Position=0, ValueFromPipeline=$true, Mandatory=$true, HelpMessage='Line of characters to process.')] 5 | [string]$line, 6 | [parameter(Position=1, HelpMessage='Type of string to process (single or double quoted)')] 7 | [string]$linetype = "'" 8 | ) 9 | if ($linetype -eq "'") { 10 | $retline = $line -replace "'","''" 11 | } 12 | else { 13 | # First normalize any already escaped characters 14 | $retline = $line -replace '`"','"' -replace "```'","'" -replace '`#','#' -replace '``','`' 15 | 16 | # Then re-escape them 17 | $retline = $retline -replace '`','``' -replace '"','`"' -replace "'","```'" -replace '#','`#' 18 | } 19 | if ($retline.length -gt 0) { 20 | $linetype + $retline + $linetype + ' + ' + '"`r`n"' 21 | } 22 | else { 23 | if ($retline -match "`r`n") { 24 | '"`r`n"' 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/public/Format-ScriptRemoveSuperfluousSpaces.ps1: -------------------------------------------------------------------------------- 1 | function Format-ScriptRemoveSuperfluousSpaces { 2 | <# 3 | .SYNOPSIS 4 | Removes superfluous spaces at the end of individual lines of code. 5 | .DESCRIPTION 6 | Removes superfluous spaces at the end of individual lines of code. 7 | .PARAMETER Code 8 | Multiple lines of code to analyze. Ignores all herestrings. 9 | .PARAMETER SkipPostProcessingValidityCheck 10 | After modifications have been made a check will be performed that the code has no errors. Use this switch to bypass this check 11 | (This is not recommended!) 12 | 13 | .EXAMPLE 14 | $testfile = 'C:\temp\test.ps1' 15 | $test = Get-Content $testfile -raw 16 | $test | Format-ScriptRemoveSuperfluousSpaces | Clip 17 | 18 | Description 19 | ----------- 20 | Removes all additional spaces and whitespace from the end of every non-herestring/comment in C:\temp\test.ps1 21 | 22 | .NOTES 23 | Author: Zachary Loeber 24 | Site: http://www.the-little-things.net/ 25 | 26 | 1.0.0 - Initial release 27 | .LINK 28 | https://github.com/zloeber/FormatPowershellCode 29 | .LINK 30 | http://www.the-little-things.net 31 | #> 32 | [CmdletBinding()] 33 | param( 34 | [parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true, HelpMessage='Lines of code to process.')] 35 | [AllowEmptyString()] 36 | [string[]]$Code, 37 | [parameter(Position = 1, HelpMessage='Bypass code validity check after modifications have been made.')] 38 | [switch]$SkipPostProcessingValidityCheck 39 | ) 40 | begin { 41 | # Pull in all the caller verbose,debug,info,warn and other preferences 42 | if ($script:ThisModuleLoaded -eq $true) { Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState } 43 | $FunctionName = $MyInvocation.MyCommand.Name 44 | Write-Verbose "$($FunctionName): Begin." 45 | 46 | $Codeblock = @() 47 | $ScriptText = @() 48 | } 49 | process { 50 | $Codeblock += ($Code -split "`r`n") 51 | } 52 | end { 53 | try { 54 | $KindLines = @($Codeblock | Format-ScriptGetKindLines -Kind "HereString*") 55 | $KindLines += @($Codeblock | Format-ScriptGetKindLines -Kind 'Comment') 56 | } 57 | catch { 58 | throw 'Unable to properly parse the code for herestrings...' 59 | } 60 | $currline = 0 61 | foreach ($codeline in ($Codeblock -split "`r`n")) { 62 | $currline++ 63 | $isherestringline = $false 64 | $KindLines | Foreach { 65 | if (($currline -ge $_.Start) -and ($currline -le $_.End)) { 66 | $isherestringline = $true 67 | } 68 | } 69 | if ($isherestringline -eq $true) { 70 | $ScriptText += $codeline 71 | } 72 | else { 73 | $ScriptText += $codeline.TrimEnd() 74 | } 75 | } 76 | 77 | $ScriptText = ($ScriptText | Out-String).Trim("`r`n") 78 | 79 | # Validate our returned code doesn't have any unintentionally introduced parsing errors. 80 | if (-not $SkipPostProcessingValidityCheck) { 81 | if (-not (Format-ScriptTestCodeBlock -Code $ScriptText)) { 82 | throw "$($FunctionName): Modifications made to the scriptblock resulted in code with parsing errors!" 83 | } 84 | } 85 | 86 | $ScriptText 87 | 88 | Write-Verbose "$($FunctionName): End." 89 | } 90 | } -------------------------------------------------------------------------------- /src/public/Format-ScriptTestCodeBlock.ps1: -------------------------------------------------------------------------------- 1 | function Format-ScriptTestCodeBlock { 2 | <# 3 | .SYNOPSIS 4 | Validates there are no script parsing errors in a script. 5 | .DESCRIPTION 6 | Validates there are no script parsing errors in a script. 7 | .PARAMETER Code 8 | Multiline or piped lines of code to process. 9 | .PARAMETER ShowParsingErrors 10 | Display parsing errors if found. 11 | .EXAMPLE 12 | PS > $testfile = 'C:\temp\test.ps1' 13 | PS > $test = Get-Content $testfile -raw 14 | PS > $test | Format-ScriptTestCodeBlock 15 | 16 | Description 17 | ----------- 18 | Takes C:\temp\test.ps1 as input and validates if the code is valid or not. Returns $true if it is, $false if it is not. 19 | 20 | .NOTES 21 | Author: Zachary Loeber 22 | Site: http://www.the-little-things.net/ 23 | Requires: Powershell 3.0 24 | 25 | Version History 26 | 1.0.0 - Initial release 27 | .LINK 28 | https://github.com/zloeber/FormatPowershellCode 29 | .LINK 30 | http://www.the-little-things.net 31 | #> 32 | [CmdletBinding()] 33 | param( 34 | [parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true, HelpMessage='Lines of code to process.')] 35 | [AllowEmptyString()] 36 | [string[]]$Code, 37 | [parameter(Position=1, HelpMessage='Display parsing errors.')] 38 | [switch]$ShowParsingErrors 39 | ) 40 | begin { 41 | $FunctionName = $MyInvocation.MyCommand.Name 42 | Write-Verbose "$($FunctionName): Begin." 43 | 44 | $Codeblock = @() 45 | $ParseError = $null 46 | $Tokens = $null 47 | } 48 | process { 49 | $Codeblock += $Code 50 | } 51 | end { 52 | $ScriptText = ($Codeblock | Out-String).trim("`r`n") 53 | Write-Verbose "$($FunctionName): Attempting to parse AST." 54 | $AST = [System.Management.Automation.Language.Parser]::ParseInput($ScriptText, [ref]$Tokens, [ref]$ParseError) 55 | 56 | if($ParseError) { 57 | if ($ShowParsingErrors) { 58 | $ParseError | Write-Error 59 | } 60 | return $false 61 | } 62 | else { 63 | return $true 64 | } 65 | Write-Verbose "$($FunctionName): End." 66 | } 67 | } -------------------------------------------------------------------------------- /src/working/Format-ScriptReplaceTabCharacters.ps1: -------------------------------------------------------------------------------- 1 | function Format-ScriptReplaceTabCharacters { 2 | <# 3 | .SYNOPSIS 4 | 5 | .DESCRIPTION 6 | 7 | .PARAMETER Code 8 | Multiline or piped lines of code to process. 9 | .PARAMETER SkipPostProcessingValidityCheck 10 | After modifications have been made a check will be performed that the code has no errors. Use this switch to bypass this check 11 | (This is not recommended!) 12 | .EXAMPLE 13 | PS > $testfile = 'C:\temp\test.ps1' 14 | PS > $test = Get-Content $testfile -raw 15 | PS > $test | Format-ScriptFormatTypeNames | clip 16 | 17 | Description 18 | ----------- 19 | Takes C:\temp\test.ps1 as input, formats as the function defines and places the result in the clipboard 20 | to be pasted elsewhere for review. 21 | 22 | .NOTES 23 | Author: Zachary Loeber 24 | Site: http://www.the-little-things.net/ 25 | Requires: Powershell 3.0 26 | 27 | Version History 28 | 1.0.0 - Initial release 29 | #> 30 | [CmdletBinding()] 31 | param( 32 | [parameter(Position = 0, Mandatory=$true, ValueFromPipeline=$true, HelpMessage='Lines of code to process.')] 33 | [AllowEmptyString()] 34 | [string[]]$Code, 35 | [parameter(Position = 1, HelpMessage='Bypass code validity check after modifications have been made.')] 36 | [switch]$SkipPostProcessingValidityCheck 37 | ) 38 | begin { 39 | # Pull in all the caller verbose,debug,info,warn and other preferences 40 | Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState 41 | $FunctionName = $MyInvocation.MyCommand.Name 42 | Write-Verbose "$($FunctionName): Begin." 43 | 44 | $Codeblock = @() 45 | $ParseError = $null 46 | $Tokens = $null 47 | } 48 | process { 49 | $Codeblock += $Code 50 | } 51 | end { 52 | $ScriptText = $Codeblock | Out-String 53 | Write-Verbose "$($FunctionName): Attempting to parse AST." 54 | $AST = [System.Management.Automation.Language.Parser]::ParseInput($ScriptText, [ref]$Tokens, [ref]$ParseError) 55 | 56 | if($ParseError) { 57 | $ParseError | Write-Error 58 | throw "$($FunctionName): Will not work properly with errors in the script, please modify based on the above errors and retry." 59 | } 60 | 61 | for($t = $Tokens.Count - 2; $t -ge 1; $t--) { 62 | $token = $tokens[$t] 63 | 64 | # Process token replacement or some such 65 | } 66 | 67 | # Validate our returned code doesn't have any unintentionally introduced parsing errors. 68 | if (-not $SkipPostProcessingValidityCheck) { 69 | if (-not (Format-ScriptTestCodeBlock -Code $ScriptText)) { 70 | throw "$($FunctionName): Modifications made to the scriptblock resulted in code with parsing errors!" 71 | } 72 | } 73 | 74 | $ScriptText 75 | Write-Verbose "$($FunctionName): End." 76 | } 77 | } -------------------------------------------------------------------------------- /src/working/Format-ScriptTemplateFunction.ps1: -------------------------------------------------------------------------------- 1 | function Format-ScriptTemplateFunction { 2 | <# 3 | .SYNOPSIS 4 | 5 | .DESCRIPTION 6 | 7 | .PARAMETER Code 8 | Multiline or piped lines of code to process. 9 | .PARAMETER SkipPostProcessingValidityCheck 10 | After modifications have been made a check will be performed that the code has no errors. Use this switch to bypass this check 11 | (This is not recommended!) 12 | .EXAMPLE 13 | PS > $testfile = 'C:\temp\test.ps1' 14 | PS > $test = Get-Content $testfile -raw 15 | PS > $test | Format-ScriptFormatTypeNames | clip 16 | 17 | Description 18 | ----------- 19 | Takes C:\temp\test.ps1 as input, formats as the function defines and places the result in the clipboard 20 | to be pasted elsewhere for review. 21 | 22 | .NOTES 23 | Author: Zachary Loeber 24 | Site: http://www.the-little-things.net/ 25 | Requires: Powershell 3.0 26 | 27 | Version History 28 | 1.0.0 - Initial release 29 | #> 30 | [CmdletBinding()] 31 | param( 32 | [parameter(Position = 0, Mandatory = $true, ValueFromPipeline=$true, HelpMessage='Lines of code to process.')] 33 | [AllowEmptyString()] 34 | [string[]]$Code, 35 | [parameter(Position = 1, HelpMessage='Bypass code validity check after modifications have been made.')] 36 | [switch]$SkipPostProcessingValidityCheck 37 | ) 38 | begin { 39 | # Pull in all the caller verbose,debug,info,warn and other preferences 40 | Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState 41 | $FunctionName = $MyInvocation.MyCommand.Name 42 | Write-Verbose "$($FunctionName): Begin." 43 | 44 | $Codeblock = @() 45 | $ParseError = $null 46 | $Tokens = $null 47 | } 48 | process { 49 | $Codeblock += $Code 50 | } 51 | end { 52 | $ScriptText = $Codeblock | Out-String 53 | Write-Verbose "$($FunctionName): Attempting to parse AST." 54 | $AST = [System.Management.Automation.Language.Parser]::ParseInput($ScriptText, [ref]$Tokens, [ref]$ParseError) 55 | 56 | if($ParseError) { 57 | $ParseError | Write-Error 58 | throw "$($FunctionName): Will not work properly with errors in the script, please modify based on the above errors and retry." 59 | } 60 | 61 | for($t = $Tokens.Count - 2; $t -ge 1; $t--) { 62 | $token = $tokens[$t] 63 | 64 | # Process token replacement or some such 65 | } 66 | 67 | # Validate our returned code doesn't have any unintentionally introduced parsing errors. 68 | if (-not $SkipPostProcessingValidityCheck) { 69 | if (-not (Format-ScriptTestCodeBlock -Code $ScriptText)) { 70 | throw "$($FunctionName): Modifications made to the scriptblock resulted in code with parsing errors!" 71 | } 72 | } 73 | 74 | $ScriptText 75 | Write-Verbose "$($FunctionName): End." 76 | } 77 | } -------------------------------------------------------------------------------- /src/working/Get-FunctionParameters.ps1: -------------------------------------------------------------------------------- 1 | function Get-FunctionParameters { 2 | <# 3 | .SYNOPSIS 4 | Return all parameters for each function found in a code block. 5 | .DESCRIPTION 6 | Return all parameters for each function found in a code block. 7 | .PARAMETER Code 8 | Multi-line or piped lines of code to process. 9 | .EXAMPLE 10 | PS > $testfile = 'C:\temp\test.ps1' 11 | PS > $test = Get-Content $testfile -raw 12 | PS > $test | Get-FunctionParameters | clip 13 | 14 | Description 15 | ----------- 16 | Takes C:\temp\test.ps1 as input, remove statement separators and puts the result in the clipboard 17 | to be pasted elsewhere for review. 18 | 19 | .NOTES 20 | Author: Zachary Loeber 21 | Site: http://www.the-little-things.net/ 22 | Requires: Powershell 3.0 23 | 24 | Version History 25 | 1.0.0 - Initial release 26 | #> 27 | [CmdletBinding()] 28 | param( 29 | [parameter(Position=0, ValueFromPipeline=$true, HelpMessage='Lines of code to process.')] 30 | [string[]]$Code 31 | ) 32 | begin { 33 | #Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState 34 | $FunctionName = $MyInvocation.MyCommand.Name 35 | Write-Verbose "$($FunctionName): Begin." 36 | 37 | $Codeblock = @() 38 | $ParseError = $null 39 | $Tokens = $null 40 | 41 | # These are essentially our AST filters 42 | $functionpredicate = { ($args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst]) } 43 | $parampredicate = { ($args[0] -is [System.Management.Automation.Language.ParameterAst]) } 44 | $typepredicate = { ($args[0] -is [System.Management.Automation.Language.TypeConstraintAst]) } 45 | $paramattributes = { ($args[0] -is [System.Management.Automation.Language.NamedAttributeArgumentAst]) } 46 | $output = @() 47 | 48 | } 49 | process { 50 | $Codeblock += $Code 51 | } 52 | end { 53 | $ScriptText = $Codeblock | Out-String 54 | Write-Verbose "$($FunctionName): Attempting to parse AST." 55 | 56 | $AST = [System.Management.Automation.Language.Parser]::ParseInput($ScriptText, [ref]$Tokens, [ref]$ParseError) 57 | 58 | if($ParseError) { 59 | $ParseError | Write-Error 60 | throw "$($FunctionName): Will not work properly with errors in the script, please modify based on the above errors and retry." 61 | } 62 | 63 | $functions = $ast.FindAll($functionpredicate, $true) 64 | 65 | # get the begin and end positions of every for loop 66 | foreach ($function in $functions) { 67 | Write-Verbose "$($FunctionName): Processing function - $($function.Name.ToString())" 68 | $Parameters = $function.FindAll($parampredicate, $true) 69 | foreach ($p in $Parameters) { 70 | $ParamType = $p.FindAll($typepredicate, $true) 71 | Write-Verbose "$($FunctionName): Processing Parameter of type [$($ParamType.typeName.FullName)] - $($p.Name.VariablePath.ToString())" 72 | $OutProps = @{ 73 | 'Function' = $function.Name.ToString() 74 | 'Parameter' = $p.Name.VariablePath.ToString() 75 | 'ParameterType' = $ParamType[0].typeName.FullName 76 | } 77 | $p.FindAll($paramattributes, $true) | Foreach { 78 | $OutProps.($_.ArgumentName) = $_.Argument.Value 79 | } 80 | $Output += New-Object -TypeName PSObject -Property $OutProps 81 | } 82 | } 83 | 84 | $Output 85 | Write-Verbose "$($FunctionName): End." 86 | } 87 | } -------------------------------------------------------------------------------- /test/Pester/Data/example-transform1.ps1: -------------------------------------------------------------------------------- 1 | $a = get-content 'C:\Users\rasputin\Dropbox\Zach_Docs\Projects\Git\ComputerAssetReport\New-AssetReportVersion2.ps1' -raw 2 | $a = get-content 'C:\Users\rasputin\Dropbox\Zach_Docs\Projects\Git\FormatPowershellCode\tests\testcase-verylargefunction.ps1' -raw 3 | $a | Format-ScriptFormatCommandNames -ExpandAliases -verbose | clip 4 | 5 | #$a | Format-ScriptReplaceHereStrings | 6 | # Format-ScriptExpandParameterBlocks | 7 | # Format-ScriptExpandStatementBlocks | 8 | # Format-ScriptExpandTypeAccelerators | 9 | # Format-ScriptCondenseEnclosures | 10 | # Format-ScriptFormatCommandNames -ExpandAliases | 11 | # Format-ScriptExpandFunctionBlocks | 12 | # Format-ScriptFormatTypeNames | 13 | # Format-ScriptPadExpressions | 14 | # Format-ScriptPadOperators | 15 | # Format-ScriptRemoveStatementSeparators | 16 | # Format-ScriptRemoveSuperfluousSpaces | 17 | # Format-ScriptReplaceHereStrings | 18 | # Format-ScriptReduceLineLength | 19 | # Format-ScriptFormatCodeIndentation | 20 | # Format-ScriptReduceLineLength | 21 | # Format-ScriptFormatCodeIndentation | 22 | # clip -------------------------------------------------------------------------------- /test/Pester/Data/newtest.ps1: -------------------------------------------------------------------------------- 1 | Write-Host($subs | Format-Table -Property @{name="Option";expression={$global:indexSub;$global:indexSub+=1}}, SubscriptionId, SubscriptionName | Out-String) -------------------------------------------------------------------------------- /test/Pester/Data/testcase-assignmentop.ps1: -------------------------------------------------------------------------------- 1 | $a=$b=$c=2 -------------------------------------------------------------------------------- /test/Pester/Data/testcase-codeblockexpansion.ps1: -------------------------------------------------------------------------------- 1 | function Format-ScriptGetKindLines {[CmdletBinding()]param([parameter(Position=0, ValueFromPipeline=$true, HelpMessage='Lines of code to process.')][string[]]$Code,[parameter(Position=1, HelpMessage='Type of AST kind to retrieve.')][string]$Kind = "*"); begin {$Codeblock = @();$ParseError = $null; $Tokens = $null; $FunctionName = $MyInvocation.MyCommand.Name; Write-Verbose "$($FunctionName): Begin."}; process{$Codeblock += $Code }; end { $ScriptText = $Codeblock | Out-String; Write-Verbose "$($FunctionName): Attempting to parse AST."; $AST = [System.Management.Automation.Language.Parser]::ParseInput($ScriptText, [ref]$Tokens, [ref]$ParseError); if($ParseError) { $ParseError | Write-Error; throw "$($FunctionName): Will not work properly with errors in the script, please modify based on the above errors and retry." }; $TokenKinds = @($Tokens | Where {$_.Kind -like $Kind}); Foreach ($Token in $TokenKinds) { New-Object psobject -Property @{ 'Start' = $Token.Extent.StartLineNumber; 'End' = $Token.Extent.EndLineNumber;}}; Write-Verbose "$($FunctionName): End." }} -------------------------------------------------------------------------------- /test/Pester/Data/testcase-condenseenclosures.ps1: -------------------------------------------------------------------------------- 1 | #comment string 2 | "Code string" 3 | if($true) #comment 4 | { 5 | 6 | 7 | 8 | 9 | "True" 10 | } 11 | 12 | $array =#here is comment string 13 | <# array entries #> 14 | 15 | @( 16 | 17 | "Test1", 18 | "TEst2" 19 | ) 20 | function Test 21 | 22 | 23 | 24 | { 25 | 26 | 27 | $a= 28 | 29 | ( 30 | "Working" 31 | ) 32 | $a 33 | } 34 | 35 | Test -------------------------------------------------------------------------------- /test/Pester/Data/testcase-strings.ps1: -------------------------------------------------------------------------------- 1 | <# This is a comment about this awsome cpu report function 2 | 3 | 4 | It has a few extra line spaces, tabs, and other stuff that should be ignored 5 | 6 | 7 | I hope you like it! 8 | #> 9 | function New-CPUReport ($Title,$Data) { 10 | $Report = @" 11 | 12 | ----------------------------------------------------- 13 | - $($Title) 14 | ----------------------------------------------------- 15 | Process ID Process Name CPU Usage 16 | 17 | "@ 18 | 19 | $ReportDataTemplate = @' 20 | <> <> <> 21 | 22 | '@ 23 | $ReportFooter = @' 24 | ----------------------------------------------------- 25 | '@ 26 | $Data | Foreach { 27 | $Report += $ReportDataTemplate -replace '<>',$_.ID -replace '<>',$_.Name -replace '<>',$_.CPU 28 | } 29 | 30 | 31 | $Report += $ReportFooter 32 | 33 | return $Report 34 | } 35 | 36 | $Data = Get-Process | Sort-Object -Property CPU -Descending | select -First 5 37 | New-CPUReport 'My Rocking Report!' $Data -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | 1.4.1 --------------------------------------------------------------------------------