Created
June 30, 2017 14:45
-
-
Save markwragg/31b81d15b308b6d72ccb61425522a76e to your computer and use it in GitHub Desktop.
PowerShell function to remove spurious whitespace from scripts. Shared by JohnLBevan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Remove-WhiteSpace { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | |
[string]$Path | |
, | |
[Parameter()] | |
[string]$Encoding = 'UTF8' #type FileSystemCmdletProviderEncoding is not public and does not match [System.Text.Encoding | |
) | |
process { | |
$tempFile = [System.IO.Path]::GetTempFileName() | |
$Path | Get-Content -Encoding $Encoding -Stream | %{"$_".TrimEnd()} | Set-Content -Path $tempFile -Encoding $Encoding | |
Move-Item -Path $tempFile -Destination $Path -Force | |
} | |
} | |
Get-ChildItem '.' -Recurse -File -Filter '*.ps1' | select -ExpandProperty fullname | Remove-WhiteSpace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment