PowerTip: Use PowerShell to Show Illegal File Name Characters


Summary: Use Windows PowerShell to display illegal characters for a file name.

Hey, Scripting Guy! Question How can I use Windows PowerShell to easily obtain a list of characters that are not permitted in file names?

Hey, Scripting Guy! Answer Use the GetInvalidFileNameChars static method from the System.IO.Path .NET Framework class:

[System.IO.Path]::GetInvalidFileNameChars()

Comments (2)

  1. Chen V says:

    Thanks for sharing really good to know this.

  2. JB says:

    That .Net method returns a collection of the illegal chars. You still need to perform a comparison to see if your proposed filename contains any member of that collection.

Skip to main content