?
Solved

tweak script to only touch user mailboxes?

Posted on 2013-01-31
10
Medium Priority
?
474 Views
Last Modified: 2013-02-05
We have a script below that resets the default calendar view appropriately for all users. However it doesnt appear to differentiate between different types of mailboxes/calendars.

How can we tweak the script below to ONLY touch user maiboxes, and skip asset/room mailboxes?

-----


<#
 
 NAME: Set-CalendarPermissions.ps1
 
 AUTHOR: Jan Egil Ring
 EMAIL: jan.egil.ring@powershell.no
 
 COMMENT: Script to set calendar-permission for mailboxes in Exchange Server 2010.
          For a list of valid AccessRights, see http://technet.microsoft.com/en-us/library/ff522363.aspx 
          More information: http://blog.powershell.no/2010/09/20/managing-calendar-permissions-in-exchange-server-2010 
 
 You have a royalty-free right to use, modify, reproduce, and
 distribute this script file in any way you find useful, provided that
 you agree that the creator, owner above has no warranty, obligations,
 or liability for such use.
 
 VERSION HISTORY:
 1.0 19.09.2010 - Initial release
 
#>
 
#requires -version 2
 
#Load Exchange Server 2010 Management Shell if not loaded. You may delete/comment out this step if you are running the script from the Exchange Management Shell
if (-not (Get-PSSnapin | Where-Object {$_.Name -like "Microsoft.Exchange.Management.PowerShell.E2010"})){
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
}
 
#Custom variables
$mailboxes = Get-Mailbox -Database "Mailbox Database xxxxxxxxx"
$AccessRights = "Reviewer"
 
#Loop through all mailboxes
foreach ($mailbox in $mailboxes) {
 
#Retrieve name of the user`s calendar
$calendar = (($mailbox.SamAccountName)+ ":\" + (Get-MailboxFolderStatistics -Identity $mailbox.SamAccountName -FolderScope Calendar | Select-Object -First 1).Name)
 
#Check if calendar-permission for user "Default" is set to the default permission of "AvailabilityOnly"
    if (((Get-MailboxFolderPermission $calendar  | Where-Object {$_.User -like "Default"}).AccessRights) -like "AvailabilityOnly" ) {
 
    Write-Host "Updating calendar permission for $mailbox..." -ForegroundColor Yellow
 
    #Set calendar-permission for user "Default" to value defined in variable $AccessRights
    Set-MailboxFolderPermission -User "Default" -AccessRights $AccessRights -Identity $calendar
    }
}
0
Comment
Question by:cameramonkey
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 5

Accepted Solution

by:
coraxal earned 1600 total points
ID: 38841040
In Exchange 2007, you could filter out the mailbox like this

$mailboxes = Get-Mailbox -Database "Mailbox Database xxxxxxxxx" -Filter '(RecipientTypeDetails -eq "UserMailbox")'

Open in new window

0
 

Author Comment

by:cameramonkey
ID: 38841089
This is exchange 2010.
0
 
LVL 52

Expert Comment

by:Manpreet SIngh Khatra
ID: 38841110
Even if its Exchange 2010 the filter isnt much changed so please try the same

- Rancy
0
A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

 

Author Comment

by:cameramonkey
ID: 38841615
Sorry, my iPhone stripped the suggestion line out of the solution when I looked at it.  From what little I know about the scripting syntax your solution should work, thx.  I just didnt know where to put it. I'll give it a whirl.
0
 
LVL 5

Expert Comment

by:coraxal
ID: 38841643
No worries, like Rancy said the Get-Mailbox doesn't change much. If anything, it adds more functionality than what it had in Exchange 2007.

In my initial post I should've said "In Exchange 2007 and (I'm sure) in Exchange 2010..." =)

You can see a more detailed explanation of the Get-Mailbox cmdlet in Exchange 2010 here

http://technet.microsoft.com/en-us/library/bb123685%28v=exchg.141%29.aspx
0
 

Author Comment

by:cameramonkey
ID: 38843719
and is there an easy way to modify the script so that it would display the proposed changes in a log but not actually DO anything? I recall seeing some powershell modules would do this.

Any script that touches everything makes me nervous when I cant preview the changes.
0
 
LVL 52

Expert Comment

by:Manpreet SIngh Khatra
ID: 38843744
Get-Mailbox only pulls info if you ever fear for changes dont use Set- Remove- some of thos

- Rancy
0
 

Author Comment

by:cameramonkey
ID: 38844004
So if I read it right, prepending the line with a # will comment it out and just display the list of accounts its going to touch in yellow on the screen?

#Check if calendar-permission for user "Default" is set to the default permission of "AvailabilityOnly" 
    if (((Get-MailboxFolderPermission $calendar  | Where-Object {$_.User -like "Default"}).AccessRights) -like "AvailabilityOnly" ) { 
 
    Write-Host "Updating calendar permission for $mailbox..." -ForegroundColor Yellow 
 
    #Set calendar-permission for user "Default" to value defined in variable $AccessRights 
    #Set-MailboxFolderPermission -User "Default" -AccessRights $AccessRights -Identity $calendar 

Open in new window

0
 
LVL 52

Expert Comment

by:Manpreet SIngh Khatra
ID: 38844122
I aint that good with Scripting so maybe you can try for one or few users and then try on a larger audience

- Rancy
0
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 400 total points
ID: 38855262
So if I read it right, prepending the line with a # will comment it out and just display the list of accounts its going to touch in yellow on the screen?
Yes, # is used in PowerShell to comment the lines

You can also use -WhatIf..
Set-MailboxFolderPermission -User "Default" -AccessRights $AccessRights -Identity $calendar -WhatIf

Open in new window

By appending the -WhatIf switch, you get a preview of what would happen if you run the command..
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
This article will help to fix the below errors for MS Exchange Server 2016 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question