locked
Exchange 2007 - Removing Public Folder trailing spaces with a CSV file? RRS feed

  • Question

  • We are able to remove the trailing spaces with the following powershell scripts.

    $trailers = Get-PublicFolder –server servername -Recurse resultsize unlimited | where{($_.name.endswith(' '))} | select identity  

     $trailers | Get-PublicFolder | %{Set-PublicFolder -Identity $_.Identity -Name $_.Name.Trim()} 

    How do I do the same thing with a CSV file?

    Here is what we have tried:

    Get-PublicFolder –server servername -Recurse resultsize unlimited | where{($_.name.endswith(' '))} | select identity |export-csv c:\psscripts\trailers.csv

     $trailers = import-csv “c:\psscripts\trailers.csv" 

     $trailers | ForEach-Object {Get-PublicFolder | %{Set-PublicFolder -Identity $_.Identity -Name $_.Name.Trim()}} 

    Here is the result we receive:

    WARNING: The command completed successfully but no settings of '\' have been modified.
    WARNING: The command completed successfully but no settings of '\' have been modified.
    WARNING: The command completed successfully but no settings of '\' have been modified.
    WARNING: The command completed successfully but no settings of '\' have been modified.
    WARNING: The command completed successfully but no settings of '\' have been modified.
    WARNING: The command completed successfully but no settings of '\' have been modified.
    WARNING: The command completed successfully but no settings of '\' have been modified.
    WARNING: The command completed successfully but no settings of '\' have been modified.
    WARNING: The command completed successfully but no settings of '\' have been modified.
    WARNING: The command completed successfully but no settings of '\' have been modified.
    WARNING: The command completed successfully but no settings of '\' have been modified.
    WARNING: The command completed successfully but no settings of '\' have been modified.

    Where are we going wrong here? Again the 1st script finds and fixes the trailing space in our Development Public folder tree.




    Thursday, March 28, 2013 2:12 PM

Answers

  • On Thu, 28 Mar 2013 14:12:54 +0000, jstubblefield wrote:
     
    >
    >
    >We are able to remove the trailing spaces with the following powershell scripts.
    >
    >
    >
    >$trailers = Get-PublicFolder –server servername -Recurse –resultsize unlimited | where{($_.name.endswith(' '))} | select identity
    >
    >
    >
    > $trailers | Get-PublicFolder | %{Set-PublicFolder -Identity $_.Identity -Name $_.Name.Trim()}
    >
    >
    >
    >How do I do the same thing with a CSV file?
    >
    >
    >
    >Here is what we have tried:
    >
    >Get-PublicFolder –server servername -Recurse –resultsize unlimited | where{($_.name.endswith(' '))} | select identity |export-csv c:\psscripts\trailers.csv
    >
    >
    >
    > $trailers = import-csv “c:\psscripts\trailers.csv"
    >
    >
    >
    > $trailers | ForEach-Object {Get-PublicFolder | %{Set-PublicFolder -Identity $_.Identity -Name $_.Name.Trim()}}
    >
    >
    >
    >Here is the result we receive:
    >
    >WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed
    >successfully but no settings of '\' have been modified.
    >
    >
    >
    >Where are we going wrong here? Again the 1st script finds and fixes the trailing space in our Development Public folder tree.
     
    I don't think you really want to use "Get-PublicFolder" without any
    arguments.
     
    In your CSV file each row has a set of named properties (i.e.
    columns). You're piping the input from get-csv into a ForEach, not
    into "get-publicfolder" so you need to use "get-publicfolder
    $_.columnname" to get the public folder you're looking for.
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    • Marked as answer by Zi Feng Wednesday, April 3, 2013 9:46 AM
    Friday, March 29, 2013 1:37 AM

All replies

  • It just occured to me that the .csv file may not be importing the trailing spaces therefore the script does not recognize the folder paths as valid.

    Thursday, March 28, 2013 5:59 PM
  • On Thu, 28 Mar 2013 14:12:54 +0000, jstubblefield wrote:
     
    >
    >
    >We are able to remove the trailing spaces with the following powershell scripts.
    >
    >
    >
    >$trailers = Get-PublicFolder –server servername -Recurse –resultsize unlimited | where{($_.name.endswith(' '))} | select identity
    >
    >
    >
    > $trailers | Get-PublicFolder | %{Set-PublicFolder -Identity $_.Identity -Name $_.Name.Trim()}
    >
    >
    >
    >How do I do the same thing with a CSV file?
    >
    >
    >
    >Here is what we have tried:
    >
    >Get-PublicFolder –server servername -Recurse –resultsize unlimited | where{($_.name.endswith(' '))} | select identity |export-csv c:\psscripts\trailers.csv
    >
    >
    >
    > $trailers = import-csv “c:\psscripts\trailers.csv"
    >
    >
    >
    > $trailers | ForEach-Object {Get-PublicFolder | %{Set-PublicFolder -Identity $_.Identity -Name $_.Name.Trim()}}
    >
    >
    >
    >Here is the result we receive:
    >
    >WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed successfully but no settings of '\' have been modified. WARNING: The command completed
    >successfully but no settings of '\' have been modified.
    >
    >
    >
    >Where are we going wrong here? Again the 1st script finds and fixes the trailing space in our Development Public folder tree.
     
    I don't think you really want to use "Get-PublicFolder" without any
    arguments.
     
    In your CSV file each row has a set of named properties (i.e.
    columns). You're piping the input from get-csv into a ForEach, not
    into "get-publicfolder" so you need to use "get-publicfolder
    $_.columnname" to get the public folder you're looking for.
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    • Marked as answer by Zi Feng Wednesday, April 3, 2013 9:46 AM
    Friday, March 29, 2013 1:37 AM