# Setting permissions on Outlook subfolders without access to inbox

**URL:** <https://forums.powershell.org/t/setting-permissions-on-outlook-subfolders-without-access-to-inbox/25152>\
**Category:** PowerShell Help\
**Created:** [December 12, 2024, 7:48pm UTC](https://forums.powershell.org/t/setting-permissions-on-outlook-subfolders-without-access-to-inbox/25152 "2024-12-12T19:48:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cvize](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@cvize](https://forums.powershell.org/u/cvize)\
**Post date:** [December 12, 2024, 7:48pm UTC](https://forums.powershell.org/t/setting-permissions-on-outlook-subfolders-without-access-to-inbox/25152/1 "2024-12-12T19:48:03Z")

</div>

Hello, I’m a very basic PS user. I just started teaching it to myself last year. The script below is supposed to add the user to every folder below Inbox\Case Files and make them the owner. I built it last year after searching online for days for help. I already gave them FolderVisible access to the Inbox and Case Files. I used this last year and it worked. Now when I try to run it on a new hire, it doesn’t do anything. And when I turned on Verbose, it looks like it tries to run but doesn’t actually change anything. I can provide that if someone wants to see it. I’ve removed the domain below but otherwise the script is intact. Can someone please take a look and tell me where it’s going wrong?

ForEach($f in (Get-EXOMailboxFolderStatistics -identity jjo | Where { $\_.FolderPath.Contains(“jjo:/Inbox/Case Files”) -eq $True } ) ) {  
$fname = “jjo:” + $f.FolderPath.Replace(“/”,"");  
Add-MailboxFolderPermission $fname -User gka -AccessRights Owner  
Write-Host $fname  
Start-Sleep -Milliseconds 1000  
}

Get-EXOMailboxFolderStatistics -identity jjo -ErrorAction Stop | Where-Object { $_.FolderPath.Contains(“jjo:/Inbox/Case Files”) } | ForEach-Object {  
Try {  
$fname = “jjo:” + $_.FolderPath.Replace(“/”,"")  
Write-Host “Amending: $fname …”  
Add-MailboxFolderPermission $fname -User gka -AccessRights Owner -ErrorAction Stop  
Write-Host “Done”  
}  
Catch {  
$\_  
}  
}  
Write-Host “Complete”

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [December 12, 2024, 9:03pm UTC](https://forums.powershell.org/t/setting-permissions-on-outlook-subfolders-without-access-to-inbox/25152/2 "2024-12-12T21:03:53Z")

</div>

Helps if you format your code with the ‘\</\>’ button. Do you get output or is it returning nothing?

---

<div class="post-metadata">

**Author:** ![cvize](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@cvize](https://forums.powershell.org/u/cvize)\
**Post date:** [December 12, 2024, 9:17pm UTC](https://forums.powershell.org/t/setting-permissions-on-outlook-subfolders-without-access-to-inbox/25152/3 "2024-12-12T21:17:46Z")

</div>

It gives me the Complete at the end but that’s it. Last year when I used it, it listed out each folder as it changed it. I don’t know what’s changed.

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [December 12, 2024, 9:45pm UTC](https://forums.powershell.org/t/setting-permissions-on-outlook-subfolders-without-access-to-inbox/25152/4 "2024-12-12T21:45:51Z")

</div>

So do you get output from just `Get-EXOMailboxFolderStatistics -identity jjo`

---

<div class="post-metadata">

**Author:** ![cvize](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@cvize](https://forums.powershell.org/u/cvize)\
**Post date:** [December 13, 2024, 2:27pm UTC](https://forums.powershell.org/t/setting-permissions-on-outlook-subfolders-without-access-to-inbox/25152/5 "2024-12-13T14:27:55Z")

</div>

Yes, it gives me tons of pages of info on the folders. Too many to even show in Powershell.

---

<div class="post-metadata">

**Author:** ![grey0ut](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grey0ut/32/5310_2.png) [@grey0ut](https://forums.powershell.org/u/grey0ut)\
**Post date:** [December 13, 2024, 5:24pm UTC](https://forums.powershell.org/t/setting-permissions-on-outlook-subfolders-without-access-to-inbox/25152/6 "2024-12-13T17:24:06Z")

</div>

Formatting your script as code on the forum is pretty much a requirement for peer review. Since you still haven’t edited your original post to format the code I decided to do it so I could read it:

```Powershell
ForEach($f in (Get-EXOMailboxFolderStatistics -identity jjo | Where-Object { $_.FolderPath.Contains("jjo:/Inbox/Case Files") -eq $True })) {
        $fname = "jjo:" + $f.FolderPath.Replace("/","");
        Add-MailboxFolderPermission $fname -User gka -AccessRights Owner
        Write-Host $fname
        Start-Sleep -Milliseconds 1000
    }
    
Get-EXOMailboxFolderStatistics -identity jjo -ErrorAction Stop | Where-Object { $.FolderPath.Contains("jjo:/Inbox/Case Files") } | ForEach-Object {
    Try {
        $fname = "jjo:" + $.FolderPath.Replace("/","")
        Write-Host "Amending: $fname …"
        Add-MailboxFolderPermission $fname -User gka -AccessRights Owner -ErrorAction Stop
        Write-Host "Done"
    } Catch {
        $_
    }
}
Write-Host "Complete"

```

And then I was able to see an issue. On line 8 after you pipe Ge-tEXOMailboxFolderStatistics to Where-Object there’s a missing underscore on the automatic variable for “Current object”.  
This:

```auto
Get-EXOMailboxFolderStatistics -identity jjo -ErrorAction Stop | Where-Object { $.FolderPath.Contains("jjo:/Inbox/Case Files") } | ForEach-Object {...

```

Should be this:

```auto
Get-EXOMailboxFolderStatistics -identity jjo -ErrorAction Stop | Where-Object { $_.FolderPath.Contains("jjo:/Inbox/Case Files") } | ForEach-Object {...

```

This would cause the Where-Object statement to return nothing, and so the Foreach-Object loop afterwards would not iterate through anything.  
And again on line 10, a missing underscore:

```auto
$fname = "jjo:" + $.FolderPath.Replace("/","")

```

These two loops are trying to accomplish the same action right? It looks like two different ways of applying the permissions. This was ran as a script?

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [December 13, 2024, 7:23pm UTC](https://forums.powershell.org/t/setting-permissions-on-outlook-subfolders-without-access-to-inbox/25152/7 "2024-12-13T19:23:59Z")

</div>

I believe the missing underscores is caused by not formatting the code and the forum strips them.

---

<div class="post-metadata">

**Author:** ![grey0ut](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grey0ut/32/5310_2.png) [@grey0ut](https://forums.powershell.org/u/grey0ut)\
**Post date:** [December 13, 2024, 11:07pm UTC](https://forums.powershell.org/t/setting-permissions-on-outlook-subfolders-without-access-to-inbox/25152/8 "2024-12-13T23:07:56Z")

</div>

ah ok that makes sense, then i suppose my last thought about why the script is doing the operation twice still stands.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [January 12, 2025, 11:08pm UTC](https://forums.powershell.org/t/setting-permissions-on-outlook-subfolders-without-access-to-inbox/25152/9 "2025-01-12T23:08:55Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
