Sep 07 2023 01:33 PM - edited Sep 07 2023 05:27 PM
Okay, I have a tiny issue. I'm okay at PS scripting, not a guru by any stretch of the imagination. So here's the situation.
Situation:
Problem:
Unable to retrieve mailbox folder statistics for mailbox <Alias>:\2023 Meetings/Trips/Events\02 February\[02/05 2:00-3:00 pm Telecon w/XYZ & Joe Smith]. Failure: Couldn't find '<Alias>:\2023 Meetings/Trips/Events\02 February\[02/05 2:00-3:00 pm Telecon w/XYZ & Joe Smith]' as a recipient.
The specified mailbox "<Alias>" doesn't exist.
The operation couldn't be performed because '<Alias>:\2023 Meetings/Trips/Events\02 February\[02/05 2:00-3:00 pm Telecon w/XYZ & Joe Smith]' couldn't be found.
+ CategoryInfo : NotSpecified: (:) [Get-MailboxFolderPermission], ManagementObjectNotFoundException
+ FullyQualifiedErrorId : [Server=ServerName,RequestId=47c592c0-dbc1-4ca5-b873-1dc5825aa23a,TimeStamp=9/7/2023 4:12:03 PM] [FailureCategory=Cmdlet-Manag
ementObjectNotFoundException] CDF486FF,Microsoft.Exchange.Management.StoreTasks.GetMailboxFolderPermission
+ PSComputerName : ServerName.domain.com
What can I do? How can I rewrite that script in order to parse that folder name correctly?
Thanks in advance,
Jim
Sep 07 2023 05:59 PM
Sep 11 2023 02:27 AM
Hi @JimBlunt,
Let´s try to solve your problem completely or at least help you to get closer to the soultion.
let's rewrite the script from your original question to handle folder names with special characters properly. We'll use the -EscapeCharacters parameter when constructing folder identities. Here's the modified script:
# Define the mailbox alias
$mailboxAlias = "<Alias>"
# Function to recursively process mailbox folder permissions
function Process-FolderPermissions($folderPath) {
$escapedFolderPath = $folderPath.Replace("/", "\")
$folderIdentity = "$mailboxAlias:`"$escapedFolderPath`""
# Get folder permissions
$folderPermissions = Get-MailboxFolderPermission -Identity $folderIdentity
# Process folder permissions as needed (e.g., set, remove, or display)
# Example: Set-MailboxFolderPermission -Identity $folderIdentity -User email address removed for privacy reasons -AccessRights FullAccess
# Display folder permissions
Write-Host "Folder: $folderPath"
$folderPermissions | Format-Table -AutoSize
# Recursively process subfolders
$subfolders = Get-MailboxFolderStatistics -Identity $mailboxAlias | Where-Object { $_.FolderPath -like "$folderPath/*" }
foreach ($subfolder in $subfolders) {
Process-FolderPermissions "$folderPath/$($subfolder.FolderName)"
}
}
# Start processing folder permissions from the root folder
Process-FolderPermissions ""
In this corrected script:
- We still define the $mailboxAlias variable to specify the mailbox alias.
- The Process-FolderPermissions function now properly escapes the folder names using the .Replace() method to replace forward slashes ("/") with backslashes ("").
- We construct the folder identity using the -EscapeCharacters parameter, which allows us to include folder names with special characters without encountering issues.
Replace <Alias> with the actual mailbox alias, and customize the permission processing logic as needed for your specific use case.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
Sep 11 2023 08:21 AM - edited Sep 15 2023 08:50 AM
Solution@LeonPavesic Over the weekend, I found something that works for me and it's only 6 lines of code. So, in the first 4 lines of code:
Once I take the output from $Perms and condense it down to a usable user list, I can run the last two: