Hi @Dick Watson ,
the underscores aren't the issue. The square brackets [
and ]
in the file name causing the trouble with Get-Item.
You can try this:
$file = 'C:\Junk\RE_ [SECURE] Re_ xxxx_ yyyy_ Closing Disclosure.pdf.AES.7z'
Get-Item -Literalpath $file
$path = "C:\Junk"
Get-ChildItem $path -File | ForEach-Object {Get-Item -Literalpath $path\$_}
# Output Get-Item
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 18.09.2021 19:55 11 RE_ [SECURE] Re_ xxxx_ yyyy_ Closing Disclosure.pdf.AES.7z
# Output Get-ChildItem
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 27.03.2021 20:07 33592 ResultServices.txt
-a---- 18.09.2021 19:55 11 RE_ [SECURE] Re_ xxxx_ yyyy_ Closing Disclosure.pdf.AES.7z
And this will delete the file without any problems:
$file = 'C:\Junk\RE_ [SECURE] Re_ xxxx_ yyyy_ Closing Disclosure.pdf.AES.7z'
Get-Item -Literalpath $file | Remove-Item
----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten