Working With Weird Filenames
Files with "--"
Use the .\ prefix for relative paths or specify the full path.
For cmdlets, you might also use the --% operator, which signals PowerShell to stop parsing the command line, passing the rest of the command directly to a native command.
Get-Content .\--weirdfilename.txtRemove-Item --% --weirdfilename.txtLeading or Trailing Spaces
Enclose the filename in quotes and use the backtick (`) as the escape character for trailing spaces in PowerShell.
Get-Content "filenameWithTrailingSpace `.txt"Remove-Item "filenameWithTrailingSpace `.txt"Wildcard Characters (*, ?)
Directly use them in quotes if they are part of the filename.
Get-Content "file*.txt"Remove-Item 'file?.txt'Last updated
Was this helpful?