function Format-PackageTextWhitespace { <# .SYNOPSIS Takes in a list of packages and replaces any/all whitespace with a single space instead. .PARAMETER PackageText List of packages, generally from a deploy job. Expected to be comma separated. #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] $PackageText ) # Take all of the endlines and put a placeholder in. $PackageText = ($PackageText -replace ("\r\n", "%")) # If this is running from powershell (ie: local testing) strings won't have \r\n, they'll have `n. Preserve that. $PackageText = ($PackageText -replace ("`n", "%")) # Shrink extra whitespace down to a single space $PackageText = ($PackageText -replace ("\s+", " ")) # Put the endline back $PackageText = ($PackageText -replace ("%", "`n")) $PackageText = $PackageText.Trim() return $PackageText }