Remove-InvalidCharacters/Remove-InvalidCharacters.ps1
2024-12-04 11:18:29 -07:00

14 lines
406 B
PowerShell

Function Remove-InvalidCharacters {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$String,
[Parameter(Mandatory=$false)]
$ReplacementCharacter = ''
)
$InvalidCharacters = [RegEx]::Escape(-join $([System.IO.Path]::GetInvalidFileNameChars()))
return [RegEx]::Replace($String, "[$InvalidCharacters]", $ReplacementCharacter)
}