Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: Windows Server 2003 and Exchange 2003

HTVi
TV Discussion Newsgroups

Windows Server 2003 and Exchange 2003
Ronnie 5/16/2007 11:38:03 AM
I work in a school and every year we have to create hundreds of user accounts
and email accounts, similarly at the end of the year we have to delete
hundreds of leavers.

Is there any script out there that could do these tasks for us?

I've seen scripts to make user accounts but that's only half the story, what
about the email accounts as well?

Am I the only one who can't find a solution to this problem?
Re: Windows Server 2003 and Exchange 2003
Jeffery Hicks <"jhicks[at]SAPIEN.com"> 5/16/2007 1:55:43 PM
On Wed, 16 May 2007 04:38:03 -0700, Ronnie wrote:

[Quoted Text]
> I work in a school and every year we have to create hundreds of user accounts
> and email accounts, similarly at the end of the year we have to delete
> hundreds of leavers.
>
> Is there any script out there that could do these tasks for us?
>
> I've seen scripts to make user accounts but that's only half the story, what
> about the email accounts as well?
>
> Am I the only one who can't find a solution to this problem?

Here are the basics for creating a user account:
http://www.microsoft.com/technet/scriptcenter/scripts/ad/users/default.mspx?mfr=true

Here's a function you can use to create the Exchange mailbox:
'Create Mailbox Function
Sub MakeMail(objUser)
On Error Resume next
'you must have Exchange Administrator Tools installed or run this on the
exchange server
strMailDN="CN=Mailbox Store (TRINITY),CN=First Storage
Group,CN=InformationStore," &_
"CN=TRINITY,CN=Servers,CN=First Administrative Group,CN=Administrative
Groups," &_
"CN=MATRIX,CN=Microsoft
Exchange,CN=Services,CN=Configuration,DC=matrix,DC=local"

objUser.CreateMailbox strMailDN
objUser.SetInfo
If Err.Number <>0 Then
WScript.Echo "Error creating mailbox for " & objUser & " on " & strMailDN
WScript.Echo Err.Number & " " & Err.Description
End If

End sub

You have to specify the DN of the mailbox store where the mailbox is to be
created. That's the hardest part.

Finally, here's some code you can use to list all the mailbox stores:
'Get list of Mailbox Stores
Dim objRootDSE
Dim objConfiguration
Dim conn
Dim cmd
Dim RS

Set objRootDSE = GetObject("LDAP://rootDSE")
strConfiguration = "LDAP://" & objRootDSE.Get("configurationNamingContext")
Set objConfiguration = GetObject(strConfiguration)
strPath=objConfiguration.ADSpath

strQuery="Select distinguishedname,name,whencreated from '" & strPath &_
"' WHERE objectclass='msExchPrivateMDB' "

WScript.Echo strQuery & vbcrlf
set cat=GetObject("GC:")
for each obj in cat
set GC=obj
Next

set conn=Createobject("ADODB.Connection")
set cmd=CreateObject("ADODB.Command")
conn.Provider="ADSDSOObject"
conn.Open

set cmd.ActiveConnection=conn
set RS=conn.Execute(strQuery)
do while not RS.EOF
WScript.Echo RS.Fields("distinguishedname")
WScript.Echo vbTab & RS.Fields("name") & "(Created " &
RS.fields("whencreated") & ")"
rs.movenext
Loop
rs.Close
conn.Close


--
Jeffery Hicks
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com
VBScript & Windows PowerShell Training -
www.ScriptingTraining.com/classes.asp
Windows PowerShell? - www.SAPIENPress.com/powershell.asp

blog: http://blog.SAPIEN.com
blog: http://jdhitsolutions.blogspot.com

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen