Managing spaces in AddReplicaToPFRecursive.ps1 script

If you are familiar with Microsoft Exchange 2007 you already know about the AddReplicaToPFRecursive.ps1 script that can be found in the “X:\Program Files\Microsoft\Exchange Server\Scripts”, however this script has a bug it doesn’t look to support public folders which names contains spaces.

It is quite common to enclose parameters that contains spaces with “quotations” but that doesn’t work here.

If you simply try to use the following it will fail.

AddReplicatoPFRecursive.ps1 -TopPublicFolder “\PublicFolder with space” -ServerToAdd “servername”

The solution turned out to be to use single quotes inside the double quotes so it should be something like

AddReplicatoPFRecursive.ps1 -TopPublicFolder “'\PublicFolder with space'” -ServerToAdd “servername”

That’s really weird and not standard but it works !

I have been working in IT consultancy and solution integration since 1998 and I consider myself lucky to be, one in a few, making a living out of my passion. I am also member of the famous Experts Exchange (profile here) online community where I try my best to share what I have learned along the road.

Posted in Messaging & Collaboration Tagged with: , , , ,
7 comments on “Managing spaces in AddReplicaToPFRecursive.ps1 script
  1. mir says:

    That must have been tricky to catch

  2. Anis Achek says:

    Thanks for the clue. Very helpful.

  3. Steffen says:

    How do i recursivly remove a server?

  4. Staffs964 says:

    Excellent Thank You
    staffs964 (experts exchange)

  5. Tawney says:

    Just a note, perhaps explain why it needs to be encapsulated twice? I know the reason why, but others may not understand the concept. It is because it passes that string to the script, but the script ommits the quotation marks. Because shell scripts accept both ' and ” to encapsulate spaces, it accepts the ' inside the script – but ommits the ” as it passes through the value.

  6. Khrebin says:

    You can use:

    AddReplicatoPFRecursive.ps1 -TopPublicFolder 'PublicFolder with space' -ServerToAdd “servername”

    – meens spec simbol.
    If you don't need interpretation of text string you must use '$i' instead of “$i”

  7. 123 says:

    You saved me so much work, thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*