Only Allow A-Za-z0-9 and spaces (how?)

%3CLINGO-SUB%20id%3D%22lingo-sub-2211155%22%20slang%3D%22en-US%22%3EOnly%20Allow%20A-Za-z0-9%20and%20spaces%20(how%3F)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2211155%22%20slang%3D%22en-US%22%3E%3CP%3E%3CFONT%3EHi%2C%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%3EThis%20powershell%20command%20removes%20all%20characters%20from%20a%20filename%20except%20A-Za-z0-9.%26nbsp%3B%3CBR%20%2F%3EGet-Item%20.%5C*.msg%20%7C%20Rename-Item%20-NewName%20%7B%20%24(%24_.BaseName%20-replace%20%22%2FW%22%2C%22%20%22)%20%2B%20%24_.Extension%20%7D%20%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%3EBut%20it%20also%20removes%20spaces%2C%20please%20help%20to%20adjust%20the%20command%20line%20into%20a%20command%20that%20only%20allows%20%26nbsp%3B%20%26nbsp%3B%20A-Za-z0-9%20and%3CFONT%20color%3D%22%23000000%22%3E%3CFONT%20color%3D%22%23ff0000%22%3E%20spaces%3C%2FFONT%3E!%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23000000%22%3ERegards%2C%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%23000000%22%3EEdward%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2211155%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Visitor

Hi,

 

This powershell command removes all characters from a filename except A-Za-z0-9. 
Get-Item .\*.msg | Rename-Item -NewName { $($_.BaseName -replace "/W"," ") + $_.Extension }

But it also removes spaces, please help to adjust the command line into a command that only allows     A-Za-z0-9 and spaces!

 

Regards,

 

Edward

0 Replies