[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

tweak script to only touch user mailboxes?

Posted on 2013-01-31
10
Medium Priority
?
473 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
Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

 

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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

One-stop solution for Exchange Administrators to address all MS Exchange Server issues, which is known by the name of Stellar Exchange Toolkit.
Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

656 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