I'm trying to move all files from a NAS to a cloud provider, which does not allow the char ?<>|/\\*:"
in its filenames, unfortunately some of the files do have these char in their filenames.
So I would like to fix these filenames before doing the migration, and thus I had the idea to list the forbiden filenames, but the forbiden char crash the Get-childItem command and I'm a bit stuck
Here's the command I use
Get-ChildItem $myPath -Recurse -Force -File | Where-Object {$_.name -match '[?<>|/\\*:"]+'} | select fullname, name
And here's the output I get :
Get-ChildItem : The given path's format is not supported
Char, Line:1 : 1
+ Get-ChildItem path -Recurse -Force ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ChildItem], NotSupportedException
+ FullyQualifiedErrorId : System.NotSupportedException,Microsoft.PowerShell.Commands.GetChildItemCommand
Is there a way to make the command fail but still tell me where was the file which crashed it ? Or is there another command or parameter to use to do what I want ?
Edit : For now I found a workaround, rather than mounting the distant nas with New-PSDrive, I sshed into the NAS and used the linux bash which was installed on it and supports these filenames but I am still interested by the answer to how to do it with powershell