Thursday, May 12, 2005

Changing the default permissions on a calendar to Reviewer

Updated 3/8/2005 to update local freebusy folder permissions to editor

Changing the default permissions on user’s calendars to reviewer is something that comes up now and again in different companies for different reasons. Automating this with script is relatively straight forward if you use the ACL.dll which you can get a copy of from the sample on CDOLive http://www.cdolive.com/aclviewer.htm.

Actually the day after I wrote the below script I found another utility that someone had created call setperm that gives you a nice GUI to this. As well as that it gives you the ability to change permissions on other folders other then the calendar. The original web site that hosted this utility seems to be gone now (which is a shame it because it had some good stuff) but you can still download the utility from http://www.slipstick.com/files/setperm.zip . There's also a third party application from Symprex that can do this go here for details.

If your still interested in the script version here it is it mostly based around http://support.microsoft.com/?kbid=240911 . Some ADSI has been added to select all the users from the GAL for a particular server in the servername variable and some file logging is done to track all the user that are updated. I’ve put a downloadable copy of the code here the script looks like

Public Const CdoDefaultFolderCalendar = 0
servername = wscript.arguments(0)
set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strNameingContext = iAdRootDSE.Get("configurationNamingContext")
strDefaultNamingContext = iAdRootDSE.Get("defaultNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
svcQuery = "<LDAP://" & strNameingContext &
">;(&(objectCategory=msExchExchangeServer)(cn=" & Servername &
"));cn,name,legacyExchangeDN;subtree"
Com.ActiveConnection = Conn
Com.CommandText = svcQuery
Set Rs = Com.Execute
while not rs.eof
GALQueryFilter = "(&(&(&(& (mailnickname=*)(!msExchHideFromAddressLists=TRUE)(|
(&(objectCategory=person)(objectClass=user)(msExchHomeServerName=" &
rs.fields("legacyExchangeDN") & ")) )))))"
strQuery = "<LDAP://" & strDefaultNamingContext & ">;" & GALQueryFilter &
";distinguishedName,mail,mailnickname;subtree"
com.Properties("Page Size") = 100
Com.CommandText = strQuery
Set Rs1 = Com.Execute
while not Rs1.eof
call dofreebusy(servername,rs1.fields("mailnickname"))
wscript.echo "Setting Permission on: " & rs1.fields("mailnickname")
rs1.movenext
wend
rs.movenext
wend
rs.close
set conn = nothing
set com = nothing
wscript.echo "Done"


function dofreebusy(servername,mailboxname)

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "","",false,true,true,true,servername & vbLF & mailboxname
Set CdoInfoStore = objSession.GetInfoStore
Set CdoFolderRoot = CdoInfoStore.RootFolder
Set ACLObj = CreateObject("MSExchange.aclobject")
set cdocalendar = objSession.GetDefaultFolder(CdoDefaultFolderCalendar)
ACLObj.CDOItem = cdocalendar
Set FolderACEs = ACLObj.ACEs
getpermissions = mailboxname & ": "
For each fldace in FolderACEs
if fldace.ID = "ID_ACL_DEFAULT" then
fldace.rights = 1025
ACLObj.update
end if
getpermissions = getpermissions & fldace.ID & "-" & fldace.rights
Next
'FreeBusy Update
Set objRoot = objSession.GetFolder("")
Set objFreeBusyFolder = objRoot.Folders.Item("FreeBusy Data")
ACLObj.CDOItem = objFreeBusyFolder
Set FolderACEs = ACLObj.ACEs
For each fldace in FolderACEs
if fldace.ID = "ID_ACL_DEFAULT" then
fldace.rights = 1123
ACLObj.update
end if
Next

End function

7 comments:

Anonymous said...

Fantastic - used the code against my AD Ex 2003 environment - it worked ! .. ps the Setperm code works perfectly in Exc 5.5 environment - I know the guy who produced it (K. Snook)

Anonymous said...

Glen, I often use your scripts as a starting point for manipulating things related to Exchange in my environment. Recently, my company decided to change the default calendar permission, so I used this script as a springboard.

I added email notification to users, email report to the admin, and noting which users have been changed already so the script can be scheduled. The link to my posting is http://www.flobee.net/default.asp?view=plink&id=132.

Thanks for the work you do.

Scott

Anonymous said...

I would like to test this script, i need to change Calendar permissions on some users, but i do not know hoy to run the script...
I guess it will be something like "cscript script.vbs parameters" but that is just my best guess...

kun said...

How to use this scripts?

EWS?

Thanks

Glen said...

This script uses Mapi via CDO 1.2 and the ACL.dll. I suggest reading the post if you want to use this as it does contains some important information. If your looking for a powershell equivalent that uses EWS on Exchange 2007 have a look at http://gsexdev.blogspot.com/2008/03/class-library-helper-for-setting.html

Cheers
Glen

Selman said...

Hi,

Is there any script that can set Per-User Recipient Limit?

Thank you in advance.

Glen said...

You can just use Set-mailbox eg

set-mailbox "mailbox Name" -RecipientLimits 100

cheers
Glen