Skip to content

Instantly share code, notes, and snippets.

@turboBasic
Last active July 8, 2017 23:37
Show Gist options
  • Save turboBasic/50c6ea536150d5fdcbfa2ff5fc88391d to your computer and use it in GitHub Desktop.
Save turboBasic/50c6ea536150d5fdcbfa2ff5fc88391d to your computer and use it in GitHub Desktop.
Test if $fileName is valid file name. Answers question "How do I check if $fileName is completely valid file name in Windows 10?"
Function Test-FilenameValid {
PARAM( [PARAMETER( Mandatory )]
[String]
$filename
)
# IndexOfAny returns -1 if there is no any characters from argument in the string
$filename.IndexOfAny( [System.IO.Path]::GetInvalidFileNameChars() ) -eq -1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment