Exchange Mailbox SIDs
Exchange Server Forum Index Exchange Server
Discussion forums for Microsoft Exchange Server users.
Microsoft Outlook
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web ExchangeServerHelp.com
Exchange Mailbox SIDs

 
Post new topic   Reply to topic    Exchange Server Forum Index -> Development
Author Message
Vince Keller
Guest





Posted: Sun Nov 20, 2005 9:58 am    Post subject: Exchange Mailbox SIDs Reply with quote

Hello,

I need to retrieve the SID (User Security Identifiers) for all the mailboxes
of the Exchange Servers that we have. I would like to know how can I
retrieve this information using either Active Directory or WMI.

Any help would be deeply appreciated.

Thanks.

Back to top
Glen Scales [MVP]
Guest





Posted: Mon Nov 21, 2005 1:58 am    Post subject: Re: Exchange Mailbox SIDs Reply with quote

The SID belongs to the User object the Mailbox Guid is what relates the
mailbox to the user object in AD. If you want to display the SID of every
user that has a mailbox them some simple ADSI should do the trick eg

set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strDefaultNamingContext = iAdRootDSE.Get("defaultNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
svcQuery = "<LDAP://" & strDefaultNamingContext &
">;(&(mailnickname=*)(objectClass=user));cn,name,objectSID,legacyExchangeDN;subtree"
Com.ActiveConnection = Conn
Com.CommandText = svcQuery
Set Rs = Com.Execute
while not rs.eof
wscript.echo "User: " & rs.fields("cn")
wscript.echo "Sid Hex: " & OctetToHexStr(rs.fields("objectSID"))
wscript.echo "Sid Dec: " &
HexStrToDecStr(OctetToHexStr(rs.fields("objectSID")))
rs.movenext
wend
rs.close
set fso = nothing
set conn = nothing
set com = nothing
wscript.echo "Done"


Function OctetToHexStr(arrbytOctet)
' Function to convert OctetString (byte array) to Hex string Courtesy
Richard Mueller [MVP]
Dim k
OctetToHexStr = ""
For k = 1 To Lenb(arrbytOctet)
OctetToHexStr = OctetToHexStr _
& Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
Next
End Function

Function HexStrToDecStr(strSid)
Dim arrbytSid, lngTemp, j


ReDim arrbytSid(Len(strSid)/2 - 1)
For j = 0 To UBound(arrbytSid)
arrbytSid(j) = CInt("&H" & Mid(strSid, 2*j + 1, 2))
Next


HexStrToDecStr = "S-" & arrbytSid(0) & "-" _
& arrbytSid(1) & "-" & arrbytSid(8)


lngTemp = arrbytSid(15)
lngTemp = lngTemp * 256 + arrbytSid(14)
lngTemp = lngTemp * 256 + arrbytSid(13)
lngTemp = lngTemp * 256 + arrbytSid(12)


HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)


lngTemp = arrbytSid(19)
lngTemp = lngTemp * 256 + arrbytSid(18)
lngTemp = lngTemp * 256 + arrbytSid(17)
lngTemp = lngTemp * 256 + arrbytSid(16)


HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)


lngTemp = arrbytSid(23)
lngTemp = lngTemp * 256 + arrbytSid(22)
lngTemp = lngTemp * 256 + arrbytSid(21)
lngTemp = lngTemp * 256 + arrbytSid(20)


HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)


lngTemp = arrbytSid(25)
lngTemp = lngTemp * 256 + arrbytSid(24)


HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)


End Function

Cheers
Glen


"Vince Keller" <siliinvestor@hotmail.com> wrote in message
news:OlcTsyZ7FHA.3976@TK2MSFTNGP15.phx.gbl...
Quote:
Hello,

I need to retrieve the SID (User Security Identifiers) for all the
mailboxes of the Exchange Servers that we have. I would like to know how
can I retrieve this information using either Active Directory or WMI.

Any help would be deeply appreciated.

Thanks.
Back to top
Vince Keller
Guest





Posted: Mon Nov 28, 2005 5:58 pm    Post subject: Re: Exchange Mailbox SIDs Reply with quote

Thank you very much for your reply.
This is exactly what I was looking for.

VK.

"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:utJLIpi7FHA.1000@tk2msftngp13.phx.gbl...
Quote:
The SID belongs to the User object the Mailbox Guid is what relates the
mailbox to the user object in AD. If you want to display the SID of every
user that has a mailbox them some simple ADSI should do the trick eg

set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strDefaultNamingContext = iAdRootDSE.Get("defaultNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
svcQuery = "<LDAP://" & strDefaultNamingContext &
">;(&(mailnickname=*)(objectClass=user));cn,name,objectSID,legacyExchangeDN;subtree"
Com.ActiveConnection = Conn
Com.CommandText = svcQuery
Set Rs = Com.Execute
while not rs.eof
wscript.echo "User: " & rs.fields("cn")
wscript.echo "Sid Hex: " & OctetToHexStr(rs.fields("objectSID"))
wscript.echo "Sid Dec: " &
HexStrToDecStr(OctetToHexStr(rs.fields("objectSID")))
rs.movenext
wend
rs.close
set fso = nothing
set conn = nothing
set com = nothing
wscript.echo "Done"


Function OctetToHexStr(arrbytOctet)
' Function to convert OctetString (byte array) to Hex string Courtesy
Richard Mueller [MVP]
Dim k
OctetToHexStr = ""
For k = 1 To Lenb(arrbytOctet)
OctetToHexStr = OctetToHexStr _
& Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
Next
End Function

Function HexStrToDecStr(strSid)
Dim arrbytSid, lngTemp, j


ReDim arrbytSid(Len(strSid)/2 - 1)
For j = 0 To UBound(arrbytSid)
arrbytSid(j) = CInt("&H" & Mid(strSid, 2*j + 1, 2))
Next


HexStrToDecStr = "S-" & arrbytSid(0) & "-" _
& arrbytSid(1) & "-" & arrbytSid(8)


lngTemp = arrbytSid(15)
lngTemp = lngTemp * 256 + arrbytSid(14)
lngTemp = lngTemp * 256 + arrbytSid(13)
lngTemp = lngTemp * 256 + arrbytSid(12)


HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)


lngTemp = arrbytSid(19)
lngTemp = lngTemp * 256 + arrbytSid(18)
lngTemp = lngTemp * 256 + arrbytSid(17)
lngTemp = lngTemp * 256 + arrbytSid(16)


HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)


lngTemp = arrbytSid(23)
lngTemp = lngTemp * 256 + arrbytSid(22)
lngTemp = lngTemp * 256 + arrbytSid(21)
lngTemp = lngTemp * 256 + arrbytSid(20)


HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)


lngTemp = arrbytSid(25)
lngTemp = lngTemp * 256 + arrbytSid(24)


HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)


End Function

Cheers
Glen


"Vince Keller" <siliinvestor@hotmail.com> wrote in message
news:OlcTsyZ7FHA.3976@TK2MSFTNGP15.phx.gbl...
Hello,

I need to retrieve the SID (User Security Identifiers) for all the
mailboxes of the Exchange Servers that we have. I would like to know how
can I retrieve this information using either Active Directory or WMI.

Any help would be deeply appreciated.

Thanks.




Back to top
 
Post new topic   Reply to topic    Exchange Server Forum Index -> Development All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server Dedicated Servers
Contact Us
New Topics Powered by phpBB