Parsing variable to add calendar rights

Marvin de Wijs
Marvin de Wijs used Ask the Experts™
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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished 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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial