This example removes a public folder called "My Public Folder" from all public folder databases in an Exchange environment.
Remove-PublicFolder -Identity "\My Public Folder"
If you want to remove "My Public Folder" on a specific Exchange server, you can do this with the following command:
Remove-PublicFolder -Identity "\My Public Folder" -Server Server01
If I want to list all public folders on a particular server I can do this with the following command:
Get-PublicFolder -Server Server01 -Recurse
Easy stuff right? The problem I found however was with the following command:
Get-PublicFolder -Server Server01 -Recurse | Remove-PublicFolder
Here I piped the output of the Get-PublicFolder command to the Remove-PublicFolder command.
Get-PublicFolder -Server Server01 -Recurse displays a list of all public folders on Server01. When piped into the Remove-PublicFolder command the Remove-PublicFolder command removes the public folders on all servers even though I only specified Server01. The pipe between the commands does not have the logic to pipe through the server I selected in the Get command, something which other Exchange cmdlets do. Definately a gotcha and something to watch out for.
To ensure this problem does not happen, you must specify which server you are removing public folders for on the Remove-PublicFolder cmdlet. For example:
Remove-PublicFolder -Identity "\My Public Folder" -Server "My Server"
Hopefully this will avoid you restoring from backup as I found myself doing today.