Saturday, January 22, 2011

Exchange Bulk Mailbox Rights Export Script

on error resume next
ServerName="DomainControlarName"
Const ForReading = 1
Set oFSO = CreateObject("scripting.filesystemobject")

set oLogPermissions = oFSO.CreateTextFile("C:\Scripts\permissions.csv")
oLogPermissions.WriteLine "DN,Trustee,AccessMask,ACEType,ACEFlags,Flags,ObjectType,InheritedObjectType"
Set oTF = oFSO.OpenTextFile("C:\Scripts\mailbox.txt",ForReading,True)

Do While Not otf.AtEndOfStream
DN = otf.ReadLine
sUserADsPath = "LDAP://"& ServerName &"/" & DN
'msgbox sUserADsPath

Set myUser = GetObject(sUserADsPath)

myuser.GetInfoEx Array("msExchMailboxSecurityDescriptor"),0
Set oSecurityDescriptor = myuser.Get("msExchMailboxSecurityDescriptor")
Set dacl = oSecurityDescriptor.DiscretionaryAcl

For Each ace In dacl
oLogPermissions.WriteLine chr(34) & DN & chr(34) &"," & ace.Trustee &"," & decodeaccessmask(ace.AccessMask) &"," & ace.AceType &"," & decodeAceFlags(ace.AceFlags) &"," & ace.Flags &"," & ace.ObjectType &"," & ace.InheritedObjectType
Next
Loop

oLogPermissions.close
oTF.close

msgbox "All Permissions are written to file..."

Function decodeAccessMask(m)
Dim s
'If m AND 1048576 Then s = s + "Synchronize;"
If m AND 524288 Then s = s + "Take Ownership;"
If m AND 262144 Then s = s + "Change Permissions;"
If m AND 131072 Then s = s + "Read Permissions;"
If m AND 65536 Then s = s + "Delete Permissions;"
If m AND 256 Then s = s + "Write Attr;"
'If m AND 128 Then s = s + "Read Attr;"
'If m AND 64 Then s = s + "Delete Dir;"
'If m AND 32 Then s = s + "Execute;"
'If m AND 16 Then s = s + "Write ExtAttr;"
'If m AND 8 Then s = s + "Read ExtAttr;"
If m AND 4 Then s = s + "Assocaited External Account;"
'If m AND 2 Then s = s + "Write;"
If m AND 1 Then s = s + "Full Mailbox Access;"
decodeAccessMask = s &"(" & m & ")"
End Function

Function decodeAceFlags(m)
Dim s
If m AND 16 Then s = s + "Has been inherited;"
If m AND 8 Then s = s + "Not effective will be inherited;"
If m AND 4 Then s = s + "Children will not pass on;"
If m AND 2 Then s = s + "Containers will inherit and pass on;"
If m AND 1 Then s = s + "Non-containers will inherit and pass on;"
decodeAceFlags = s &"(" & m & ")"
End Function

No comments:

Post a Comment