Solved

tweak script to only touch user mailboxes?

Posted on 2013-01-31
10
459 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PowerShell .lastLogonTimestamp off 11 26
Recycle MSExchnge powershell app Pool 2 17
Xenapp 6.5 Powershell question 9 18
Yes, Powershell again 5 10
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
This video discusses moving either the default database or any database to a new volume.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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