?
Solved

tweak script to only touch user mailboxes?

Posted on 2013-01-31
10
Medium Priority
?
469 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Need protection from advanced malware attacks?

Look no further than WatchGuard's Total Security Suite, providing defense in depth against today's most headlining attacks like Petya 2.0 and WannaCry. Keep your organization out of the news with protection from known and unknown threats.

 

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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2013 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…
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
In this video we show how to create a Contact 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 Recipients >> Contact ta…
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…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

770 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