We help IT Professionals succeed at work.

Parsing variable to add calendar rights

Marvin de Wijs
on
I try to add myself to all calendars with review rights in my company (Dutch language, hence the Agenda instead of Calendar).
Unfortunately $user:\Agenda  isn't parsed because the : will be added to the $user variable.

Marked error
Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox') -and (Alias -ne 'Admin')} | ForEach-Object {
    $user = $_.SamAccountName
    Add-MailboxFolderPermission -identity $user:\Agenda -User me@company -AccessRights Reviewer
}

Open in new window


How could I fix this?

Many thanks in advance!
Comment
Watch Question

Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
Use a subexpression $():
Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox') -and (Alias -ne 'Admin')} | ForEach-Object {
    Add-MailboxFolderPermission -identity "$($_.SamAccountName):\Agenda" -User me@company -AccessRights Reviewer
}

Open in new window

Marvin de WijsIT Consultant

Author

Commented:
Many thanks, exactly what I was looking for.