How to user PowerShell -replace to remove the dreaded em dash from a file name?

I have a bunch of .msg files in a directory and want to zip them up (to send them to our spam filtering company), but I keep getting errors on file names that contain the em dash (—).  I believe it's (char)0x2014.
[edited]... the correct syntax is [char]0x2014.
I wish to eliminate the em dash in the file name but I can't seem to find anything on the web about replacing em dashes.  When I paste '—', PowerShell replaces it with a '-'.
I found this neat function that does a great job replacing multiple characters within a string.
http://powershell.com/cs/blogs/tobias/archive/2011/04/28/multiple-text-replacement-challenge.aspx
I am using the below code for my string replacement.
Thank you for your help.
function Replace-Text {
param(
[Parameter(Mandatory=$true)]
$text,
$replacementlist = "(-,,',,%,,$,,@,,#,,&,,’,"
Invoke-Expression ('$text' + -join $(
foreach($e in $replacementlist.Split(',')) {
'.Replace("{0}","{1}")' -f $e, $(
[void]$foreach.MoveNext()
$foreach.Current)
$path = '<path>'
Get-ChildItem -Path $path | Rename-Item -NewName {(Replace-Text $_.Name).trim()}

Here is a simple filter that will strip out all nonprintable chanracters.
$newname=$file.Name -replace '[^a-zA-Z\.]'
I just tested it on Win 7 which supports has a Unicode filesystem and it successfullstrips the bad characters.
We also need to do this on files uploaded to SharePoint and OneDrive.
The ~ and other similar characters are not allowed in may systems.  You should keep a translation log and tag all renamed files with some obvious tag.
¯\_(ツ)_/¯

Similar Messages

  • How do I remove the floating home button from my phone?

    How do I remove the floating home button from my iPhone 4? It was originally installed by the Apple Genius Bar because my home button was not working, but I have now bought a replacement iPhone 4 (where the home button works) and I still have the floating home button on the screen. I would like to remove it considering its no longer needed.

    Select the "Dot", then "Gestures", chose a Gesture Square, Assistive Touch, Off.

  • How can i remove the terms and conditions from my app store on iphone 5s ?

    How can i remove the terms and conditions from my app store icon on iphone 5s

    Hello mrh1962,
    Thank you for providing the details of the issue you are experiencing with accepting Terms & Conditions on your iPhone 5s.
    First, I recommend restarting your phone and then resetting if it's still not working:
    Restarting your device
    Press and hold the Sleep/Wake button for a few seconds until the red "slide to power off" slider appears, and then slide the slider.
    Press and hold the Sleep/Wake button until the Apple logo appears.
    Note: Reset your device only if you are unable to restart it.
    Resetting your device
    Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears.
    You can find the full article here:
    iPhone, iPad, iPod touch: Turning off and on (restarting) and resetting
    http://support.apple.com/kb/ht1430
    If you can access your home screen, I also recommend verifying that cookies are not blocked and private browsing is turned off in Settings>Safari:
    iPhone User Guide - Safari settings
    http://help.apple.com/iphone/7/#/iph3d7aa74dc
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • TS4036 My icloud is showing a very old email address,while myitunes / appstore email is showing the new email address? How do i remove the old email address from icloud?

    My icloud is showing a very old email address,while myitunes / appstore email is showing the new email address? How do i remove the old email address from icloud?

    Welcome to the Apple community mohinderjeet.
    If you mean that Find My Phone is asking for a password to a different Apple ID to your current Apple ID.
    This feature has been introduced to make stolen phones useless to those that have stolen them.
    However it can also arise when the user has changed their Apple ID details with Apple and not made the same changes to their iCloud account/Find My Phone on their device before upgrading to iOS 7, or if you restore from a previous back up made before you changed your details.
    The only solution is to change your Apple ID back to its previous state with Apple at My Apple ID using your current password, you don’t need access to this address if it’s previously been used with your Apple ID, once you have saved these details enter the password as requested on your device and then turn off "find my phone" and delete the account from your device.
    You should then change your Apple ID back to its current state, save it once again and then log back in using your current Apple ID. Finally, turn "find my phone" back on once again.
    This article provides more information about Activation Lock.

  • How can I remove the old apple id from my ipod 4rth gen to log in my new apple id ? (my old apple id keeps showing automatic I can't put my prefer new apple id)

    How can I remove the old apple id from my ipod 4rth gen to log in my new apple id ? (my old apple id keeps showing automatic I can't put my prefer new apple id)

    - Note that apps are locked to the account that purchased them.
    - To update apps you have to sign into the account that purchased the apps. If you have apps that need updating purchased from more than one account you have to update them one at a time until the remaining apps were purchased from one account.

  • How can i remove the previous icloud acount from my iphone4?

    I recently purchased a second hand iphone4 not jailbroken and i already restored it to factory settings but i can't log in to icloud using my account because it states that  "The maximum number of free accounts have been activated on this iPhone". How can i remove the previous icloud acount from my iphone4? Hope someone could help me on this. Cheers! :)

    Hi,
    My dad gave me his old iphone as he got an upgrade. I can't seem to change his icloud account to mine. I'm getting his updated calender and his mail - and there seems to be some confusion between both our accounts. He seems to be acquiring some of my contacts - some of which have names which have led to some probing questions... So basically this needs to be sorted out! How can i delete his account from the iphone but not his whole icloud account? he would not be happy if i did this...
    Sophie

  • I need to know how to edit a drawing - basically remove the arrows and text but at the same time match the background of the existing pic. then re add new text. how do i erase the arrows and text and arrows but match current background of pic. step by ste

    i need to know how to edit a drawing - basically remove the arrows and text but at the same time match the background of the existing pic. then re add new text. how do i erase the arrows and text and arrows but match current background of pic. step by step explanation please beginner

    Please post (a relevant section of) it right on this Forum.

  • HT1349 how  do you remove the header and footer from a document

    how  do you remove the header and footer from a document

    It depends upon the app you are using.

  • How do I cancel my purchase, remove the program an information in order to receive my money back?

    How do I cancel my purchase, remove the program an information in order to receive my money back?

    Hi Technoterri,
    You can manage your account by logging into adobe.com and taking the following steps:
    *Sign in the top right corner using your Adobe.com credentials
    *Click on your name (same location) and select ‘My products and services’
    *From there you can check on your status, log in/account info, etc.
    Let us know if this helps!
    Kind regards, Stacy

  • How can I remove the authorize 5 computer from my iTunes?

    How can I remove the authorize 5 computer from my iTunes?

    Deauthorize one computer
    Open iTunes on the computer you want to deauthorize.
    Choose Store > Deauthorize This Computer.
    You might need to show the menu bar to see this option in Windows. In earlier versions of iTunes, you can access this option from the Advanced menu.
    Enter your Apple ID.
    Click Deauthorize.
    If need to deauthorize your computer but you can't access it, you need to deauthorize all computers. After you authorize 2 computers, you'll have the option to deauthorize all computers for your Apple ID. You can deauthorize all computers once per year.
    Deauthorize your computer using iTunes - Apple Support

  • How can I remove the Emergency Call button from the lock screen Xperia Z2

    How can I remove the Emergency Call button from the lock screen on my Z2 phone

    Alecuk wrote:
     It's like the stupid bold font on the hours or the lock screen clock - i've never seen anything so stupid in all my life.
    it's things like this that make a good phone c.r.a.p.
    Hi, well if you do a little bit of research on the forum you will be able to see that you can & very easily able to change the font on the clock 

  • How to remove the system data details from the overview tab in crmd_order?

    Hi All,
    How to remove the system data details from the overview tab in crmd_order?

    Hi,
    It is a standard functionality. Those information will be very useful when you send a message to SAP.
    If you still want to remove them, raise an OSS message.
    Regards,
    Rajesh Kumar

  • How do I remove the Adobe updater icon from the menu bar?

    How can I remove the Adobe Updater icon from the menu bar? It's pixelated and looks broken. Any help is appreciated.
    I found this thread, but it doesn't work. When I click on the Updater icon, then click "Open updater," it opens the Creative Cloud instead. I haven't found a way to remove the updater icon from within Creative cloud.
    Remove Adobe Updater from OS X menu bar?
    ^^ Doesn't work
    Anyone know how to remove it?
    Thanks!

    Found it, thanks to later posts in that thread I mentioned in the OP. Here is what they suggest (you have to use Photoshop):
    1. In Photoshop, go to Help >Updates:
    2. Click "Preferences" at the bottom right.
    3. Uncheck the box labeled "Notify me of new updates on the menu bar." Then click "Ok."
    Hope that helps anyone!

  • How to remove the XML attribute value in Indesign file by javascript

    Hi all,
    How to remove the XML attribute value in Indesign file.

    Try this,
    if(elm.xmlElements[i].xmlAttributes[j].name == "aid:pstyle" || elm.xmlElements[i].xmlAttributes[j].name == "aid:cstyle")
    Vandy

  • How can I sign out or remove the old apple ID in app store's updates?

    I created a new apple id and signed in the app store. When I update my apps, it requires me to sign in with my old apple id, and I cannot sign out my old id. How can I sign out or remove the old id in app store's updates?

    Delete those applications and then download them from the new Apple ID. This may require repurchasing them.
    (100330)

Maybe you are looking for

  • After upgrading to iOS6 my e-mail no longer works. How do I get it back?

    I upgraded to iOS6 and now my e-mail no longer works. What do I do to get it back? It is stuck. I have restarted the iPad multiple times, checked my settings to no avail. I know the accouunt still works as I can access it on my PC. Help!! PLease

  • How to use template or fragment in PDF form

    Hi Expert, As required by project, I want to create a sample form only with company logo in header and address info in footer. Then this sample form can be made as a template. Any new form development will use this template form, no need to maintain

  • IGS in Nw04s BI ?

    Hi guys, i need know some issues for request to Basis for install the Server. 1) What happend by IGS in BI in SAP NetWeaver 2004s ? Is required for Graphics or is included ? 2) For implementing the Integrated Planning is required AS in JAVA or workin

  • HT5934 IOS7 PROBLEM

    I noticed that when you are in the Contacts for the IOS7 there is a search box but when you try to search there is know keyboard that pops up to search a name.  This is an error.

  • Setting Max CPU usage for individual apps.

    Is there a way to set a maximum CPU usage (percentage) for individual applications so when they run they will never go above the limit?