• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1017
  • Last Modified:

Cleaning up Public Folder aliases for migration to 2013

I'm trying to migrate my Exchange 2007 public folders to 2013 but keep running into issues with PF aliases with invalid characters.  I found this modified script to work with public folders:  http://www.johanveldhuis.nl/tools/scripts/fix-aliasv20.ps1

While it does a good job at cleaning up a lot of public folder aliases, I seem to be running into issues with aliases that contain words in parenthesis.   Any help would be much appreciated as my company has 74,000 public folders so this isn't something I can clean up manually.

Found Object to Fix: XXX (229/829) (Recovered)
 New Alias of Object: XXX_(229/829)_(Recovered)

The term ‘Recovered’ is not recognized as the name of a cmdlet, function, scrip
 t file, or operable program. Check the spelling of the name, or if a path was i
 ncluded, verify that the path is correct and try again.
 At line:1 char:117
 + set-MailPublicFolder ‘neirelocation.com/Microsoft Exchange System Objects/XXX
 (829)’ -alias XXX_(229/829)_(Recovered <<<< )
 + CategoryInfo : ObjectNotFound: (Recovered:String) [], CommandNo
 tFoundException
 + FullyQualifiedErrorId : CommandNotFoundException


Found Object to Fix: XYZ (119)
New Alias of Object: XYZ_(119)

Set-MailPublicFolder : A positional parameter cannot be found that accepts argu
ment '119'.
At line:1 char:21
+ set-MailPublicFolder <<<<  'neirelocation.com/Microsoft Exchange System Objec
ts/XYZ (119) 17819844' -alias XYZ_(119)
    + CategoryInfo          : InvalidArgument: (:) [Set-MailPublicFolder], Par
   ameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Exchange.M
   anagement.MapiTasks.SetMailPublicFolder
0
npdodge
Asked:
npdodge
  • 13
  • 10
1 Solution
 
lciprianionutCommented:
You get errors because of the (). You need to put all that into single or double quotes:
-alias "XXX_(229/829)_(Recovered)" -or -alias "XYZ_(119)"

On the script from Johan replace next line from Function FixObject
$setcommand = "set-" + $type + " '" + $value.identity + "' -alias $new"
with
$setcommand = "Set-" + $type + " '" + $value.identity + "' -alias" + " '" + $new + "'"

But if you have folders with coma in name like Mary's it will give an error.

You can replace with next one in that case
$setcommand = "Set-" + $type + " '" + $value.identity + "' -alias" + ' "' + $new + '"'

Good luck
0
 
npdodgeAuthor Commented:
So if I modify the script, how would I run it so it can replace "(" and ")" with an underscore character?
0
 
npdodgeAuthor Commented:
Would I execute the script like this?

.\fix-aliasv20.ps1 -type mailpublicfolder -search "(", ")" -replace "_", "_"
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
npdodgeAuthor Commented:
I found this script on this site (http://www.vspbreda.nl/nl/2013/12/exchange-2010-to-exchange-2013-public-folder-migration/)

Check for ‘ (‘ and ‘)’

$pfs= Get-publicfolder “\” -ResultSize Unlimited -recurse | where {$_.MailEnabled -eq “True”} | Get-MailPublicFolder | where {$_.alias -like ‘*(*’ -or $_.alias -like ‘*)*’}

write-host $pfs

foreach($pf in $pfs) {set-mailpublicfolder $pf.Identity -Alias:($pf.alias -replace ‘\(|\)’,”)}

But that didn't seem to work either.  

[PS] K:\>$pfs= Get-publicfolder "\" -ResultSize Unlimited -recurse | where {$_.M
ailEnabled -eq "True"} | Get-MailPublicFolder | where {$_.alias -like `*(*' -or
$_.alias -like `*)*'}
You must provide a value expression on the right-hand side of the '-like' opera
tor.
At line:1 char:141
+ $pfs= Get-publicfolder "\" -ResultSize Unlimited -recurse | where {$_.MailEna
bled -eq "True"} | Get-MailPublicFolder | where {$_.alias -like <<<<  `*(*' -or
 $_.alias -like `*)*'}
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
   ception
    + FullyQualifiedErrorId : ExpectedValueExpression
0
 
lciprianionutCommented:
Try to use double quotes (") instead of single one (').
0
 
npdodgeAuthor Commented:
Thanks, using double quotes worked.  After running the following command:

$pfs= Get-publicfolder “\” -ResultSize Unlimited -recurse | where {$_.MailEnabled -eq “True”} | Get-MailPublicFolder | where {$_.alias -like "*(*" -or $_.alias -like "*)*"}

I need to run write-host $pfs and then it says to run foreach($pf in $pfs) {set-mailpublicfolder $pf.Identity -Alias:($pf.alias -replace ‘\(|\)’,”)}

I'm not exactly sure what it's replacing, is it replacing each parenthesis with a comma, or is it actually deleting them?  Is the syntax above correct?
0
 
lciprianionutCommented:
Is replacing ( or ) with nothing (no character)
0
 
npdodgeAuthor Commented:
Is the syntax correct?  The reason I ask is that there is a double quote near the end of the script but I don't see one to go with it.    

‘\(|\)’,)}
0
 
lciprianionutCommented:
Is not a double quote but a single quote 2 times, for open and close and inside is nothing.
To really test this if is working as you wish test it first. Put in $pfs variable just 2 PF names ($pfs = "\folder1","\folder2" - here you need to check which format accepts Set-MailPublicFolder cmdlet, but most probably Identity is OK) and then run the foreach part, or you can put -WhatIf on set-mailpublicfolder or you can put in foreach like this
($pf in $pfs) {$NewName = $pf.alias -replace ‘\(|\)’,''; $NewName} just to test it.

Hope that all this make sense.
0
 
npdodgeAuthor Commented:
This is what I'm getting when trying to do a test:

[PS] C:\Documents and Settings\xxx>foreach($pf in $pftest) {$NewName = $pf.alias
 -replace `\(|\)',''; $NewName}
You must provide a value expression on the right-hand side of the '-replace' op
erator.
At line:1 char:55
+ foreach($pf in $pftest) {$NewName = $pf.alias -replace <<<<  `\(|\)',''; $New
Name}
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
   ception
    + FullyQualifiedErrorId : ExpectedValueExpression

Just so you can see what I entered into my variable:

[PS] C:\Documents and Settings\xxx>$pftest = "\company\client folders (inacti
ve)\client (164/264/364/564)\164 Origination\264-7760, Jane Doe","\comapny\clie
nt folders (inactive)\client (164/264/364/564)\164 Origination\164-2236, John Doe"
[PS] C:\Documents and Settings\xxx>write-host $pftest
\company\client folders (inactive)\client (164/264/364/564)\164 Origination\26
4-7760, Jane Doe \company\client folders (inactive)\client (164/264/364/564)\16
4 Origination\164-2236, John Doe
0
 
lciprianionutCommented:
PS C:\Windows\System32> $pftest = "\company\client folders (inactive)\client (164/264/364/564)\164 Origination\264-7760, Jane Doe","\comapny\client folders (inactive)\client (164/264/364/564)\164 Origination\164-2236, John Doe"

PS C:\Windows\System32> $pftest
\company\client folders (inactive)\client (164/264/364/564)\164 Origination\264-7760, Jane Doe
\comapny\client folders (inactive)\client (164/264/364/564)\164 Origination\164-2236, John Doe

PS C:\Windows\System32> foreach($pf in $pftest) {$NewName = $pf -replace '\(|\)',''; $NewName}
\company\client folders inactive\client 164/264/364/564\164 Origination\264-7760, Jane Doe
\comapny\client folders inactive\client 164/264/364/564\164 Origination\164-2236, John Doe

This will work.

This one will not work because of $pf.alias which doesn't exist, but it should work in your environment.
But are you sure is alias, because I believe is Identity what should be there ($pf.Identity). Try with this and it should work.
0
 
npdodgeAuthor Commented:
I guess I'm a little confused because I need to clean up the invalid characters in the alias, I'm not trying to rename the actual public folder.
0
 
npdodgeAuthor Commented:
Nothing seemed to have happened when I ran:
 foreach($pf in $pftest) {$NewName = $pf -replace '\(|\)',''; $NewName}

It just listed the public folders, just like it would if I would have just typed $pftest
0
 
lciprianionutCommented:
OK, if this parenthesis are in alias (I assumed they are in Identity) then it should work.

This is the Identity, right ?
$pftest = "\company\client folders (inactive)\client (164/264/364/564)\164 Origination\264-7760, Jane Doe","\comapny\client folders (inactive)\client (164/264/364/564)\164 Origination\164-2236, John Doe"

Does alias have this parenthesis in it ?
foreach($pf in $pftest) {$NewName = $pf.alias -replace '\(|\)',''; $NewName}
0
 
npdodgeAuthor Commented:
Ok, I just ran the following:

$pfs= Get-publicfolder “\” -ResultSize Unlimited -recurse | where {$_.MailEnabled -eq “True”} | Get-MailPublicFolder | where {$_.alias -like "*(*" -or $_.alias -like "*)*"}

write-host $pfs

foreach($pf in $pfs) {set-mailpublicfolder $pf.Identity -Alias:($pf.alias -replace ‘\(|\)’,'')}

and got the following error again:
You must provide a value expression on the right-hand side of the '-replace' op
erator.
At line:1 char:83
+ foreach($pf in $pfs) {set-mailpublicfolder $pf.Identity -Alias:($pf.alias -re
place <<<<  `\(|\)','')}
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
   ception
    + FullyQualifiedErrorId : ExpectedValueExpression

This is getting frustrating.... what am I doing wrong?
0
 
lciprianionutCommented:
Is the copy/paste after -replace , is the wrong quote, just write it by hand, single quote: -replace '\(|\)','')}
0
 
npdodgeAuthor Commented:
I'm doing a single quote twice.
0
 
lciprianionutCommented:
And is working or not ?
0
 
npdodgeAuthor Commented:
Is not.  Still get

You must provide a value expression on the right-hand side of the '-replace' op
 erator.
 At line:1 char:83
 + foreach($pf in $pfs) {set-mailpublicfolder $pf.Identity -Alias:($pf.alias -re
 place <<<<  `\(|\)','')}
     + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
    ception
     + FullyQualifiedErrorId : ExpectedValueExpression

This is Exchange 2007, does that make a difference?  I'm running SP3 U10
0
 
lciprianionutCommented:
Uhh, I don't have Ex2007 to check it, but I expect to not be any differences
0
 
npdodgeAuthor Commented:
I found something that worked.

Get-publicfolder "\" -ResultSize Unlimited -recurse | get-mailpublicfolder | where {$_.alias -like "* *" -or $_.alias -like "*,*"} | foreach-object {set-mailpublicfolder $_.name -alias:($_.Alias -replace '\s|\,','')}
0
 
lciprianionutCommented:
That's good to hear that's working
0
 
npdodgeAuthor Commented:
Found my own script that worked
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 13
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now