I know this has been asked already, but I am trying to use a security group and share calendars with each member of that group (each user can view each other member's calendar). I have found several scripts online that work with calendar sharing permissions, but I just can't seem to make mine work. Here is what I'm working with so far:
# Connect to Exchange Online PowerShell
Connect-ExchangeOnline
# Define the security group name
$securityGroupName = "Test Calendar"
# Get all users within the security group
$groupMembers = Get-ADGroupMember -Identity $securityGroupName
# Specify the calendar you want to share and the permissions
$calendarName = "Calendar"
$permissionLevel = "Reviewer" # Possible values: Owner, PublishingEditor, Editor, PublishingAuthor, Author, NonEditingAuthor, Reviewer, Contributor, AvailabilityOnly
# Loop through each member of the security group and share the calendar
foreach ($member in $groupMembers) {
$user = $member.PrimarySmtpAddress
Write-Host "Attempting to share calendar $calendarName with ${user}..."
try {
Write-Host "The current user is ${user}."
#Add-MailboxFolderPermission -Identity "${user}:\Calendar\$calendarName" -User Default -AccessRights $permissionLevel -ErrorAction Stop
#Write-Host "Shared calendar $calendarName with $user with $permissionLevel permission."
} catch {
Write-Host "Error sharing calendar with ${user}: $_"
}
}
Write-Host "Finished operations, disconnecting from Exhange Online."
# Disconnect from Exchange Online PowerShell
Disconnect-ExchangeOnline -Confirm:$false
I have commented out the "add-mailbox..." and "write-host" in the try statement as I seem to be having an issue with passing the $user variable currently. The output simply shows "Attempting to share calendar Calendar with ..." And "The current user is ."
I know it's something I'm doing wrong with the $member.PrimarySmtpAddress area, just can't seem to find the correct thing there.
I have tried a few variations of the "$member.[stuff here]" variable, but nothign seems to work. I've also tried something a bit different with this:
foreach ($member in $GroupMembers)
{
Add-MailboxFolderPermission -Identity (""+ $GroupMember.Guid+":\Calendar") -User $_.SamAccountName -AccessRights Reviewer
}
But that did not work either.