Solved

tweak script to only touch user mailboxes?

Posted on 2013-01-31
10
458 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 400 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
 

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
The curse of the end user strikes again      

You’ve updated all your end user’s email signatures. Hooray! But guess what? They’re playing around with the HTML, adding stupid taglines and ruining the imagery. Find out how you can save your signatures from end users today.

 

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 100 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

Do email signature updates give you a headache?

Do you feel like all of your time is spent managing email signatures? Too busy to visit every user’s desk to make updates? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today!

Join & Write a Comment

Suggested Solutions

Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
In this video we show how to create an Address List 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 Organization >> Ad…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now