|
hi,
the code works in command line and windows explorer.
i have a ms access data acces page, i am trying to use this code to work with microsoft script editor, it gave me error "object required "WScripit"' in the code line below
' Get the Arguments object
Set ArgObj = WScript.Arguments
how to amend this code in order to work in the script editor?
thanks in advance.
|
|
|
|
|
Is it possible to monitor an exchange mailbox account and trigger an event if a reply to a message also comes into the mailbox?
Let me explain, our server monitoring solution (OVOW) sends a mail to an "on-call engineer" mailbox account when their is a critical alert in our environment. This mail is then forwarded to the on-call engineer's blackberry PDA.
Is it possible for the on-call engineer to reply to a message with some keywords which the monitoring script will recognise and then trigger an action on our OVOW server e.g. acknowledge a message and move it from the critical browser.
I'm happy with how to do the second part, acknowledging the message, but don't know how I'd go about monitoring mails in the on-call mailbox.
Thank you,
Graham.
|
|
|
|
|
Hi there,
I've tried running this script but I either get no output (when I check a name that is already in exchange) or I get this error:
HasMailbox.vbs(47, 1) (null): An invalid dn syntax has been specified.
When I check a name that is not in exchange.
Any ideas on what I've done wrong?
Thanks
Tristan
|
|
|
|
|
I would suggest to check the dns string you get back from the GetObject command.
Something must be wrong with that.
Also make sure that on line 42 you have a valid Domain Controller for the Ldap requests.
You could output the sUserLDAPName variable to the screen with the msgbox command to debug.
Als check http://www.computerperformance.co.uk/Logon/code/code_80072032.htm
|
|
|
|
|
How do I check the dns string I get back from the GetObject command?
I've put the valid domain controller name in, but how can I be sure? Is there a way to check what my Domain Controller is?
When I output the sUserLDAPName vaiiable it outputs this:
CN=Tristan Carroll,CN=Users,DC=bcoach,DC=co,DC=uk
It's definately returned my name from exchange correctly in that string...
thanks,
Tris
|
|
|
|
|
Actually, I could have written the code to take the Domain Controller from the environment variables.
If you type set at the command prompt, then you see all the environment variables.
One of them is the LOGONSERVER.
That should give you the domain controller where you are logged in with.
You could change the line
DCServer = "MyMainDC"
With
DCServer = Mid(objEnv("LOGONSERVER"),3)
That should do the job (Not tested)
|
|
|
|
|
I have been asked to remove all the redundant User SMTP addresses in our Exchange. (Many SMTP addresses were created per user. Only 2 are now valid)
Can you suggest how I would do this in VBscript?
I have a comprehensive understanding of NT4 batches. Am trying to learn VBscript on the fly.. I realize this is not that simple, but if you could make some suggestions, such as basics like:
-Iterate through a text file that lists OUs that have the user names to process.
-Iterate through the user names found in the OU.
-Process each user removing all SMTP addresses except the SMTP addresses listed in another text file.
Any help or links would be appreciated.
|
|
|
|
|
Hi,
What you are suggesting needs some mayor knowledge of VBScript LDAP, CDOEX and ADSI.
I suggest to make this in dot net or in VB6.
The debugging will be very difficult is VBScripts.
What I always do, if a VBscripts is needed for some reason, then I code in VBA (Excel for example), and then I adapt the code to VBScript.
I can assure you that this is no begginners stuff. I also suggest to do this in a test domain first, because of the danger altering wron AD entries which could screw up your whole domain.
As a little help I will add some code I used to create users and e-mail addresses in some old VB6 software. Soon I will be making something simular in C# for one of my customers, so maybe I will publish an article about it.
Anyway, here some code wich could point you in the right direction.
This is not complete code, because some library's are called.
Also use ldp or some other LDAP tool, to get exact path to the OU or other AD objects.
P.S. You will learn a lot doing stuf like this.
Kind Regards
Peter Verijke
<snip>
Const DesktopUser = 1
Const TSUser = 2
Public OU As String 'e.g. OU=xxxx, OU=xxxx, OU=xxxxx,DC=domain,DC=toplevel
Public FirstName
Public LastName
Public DisplayName
Public Description
Public Initials
Public samAccountName
Public userPrincipalName 'xxxxx@xxxx.xxx
Public Title
Public Department
Public TelephoneNumber
Public Password
Public Mail 'xxxxx@xxxx.xxx
Public MailNickName
Public Name
Public LoginScript
Public HomeDirectory
Public HomeDrive
Public ProfilePath
'Public ScriptPath
Public UserType As Integer 'Bit 1=NT, 2=TS
Public CreateMailbox As Boolean
Public Sub CreateUser()
Dim oComputer As IADsComputer
Dim oIADs As IADs
Dim oUser As IADsUser
Dim oShare As IADs
Dim oContainer As IADsContainer
Dim oGroup As IADsGroup
Dim oMailbox As CDOEXM.IMailboxStore
Set oContainer = GetObject("LDAP://" & OU)
Set oUser = oContainer.Create("user", "CN=" & samAccountName)
oUser.Put "samAccountName", samAccountName
oUser.Put "userPrincipalName", userPrincipalName
oUser.SetInfo
PutAttrib oUser, "title", Title
PutAttrib oUser, "givenName", FirstName
PutAttrib oUser, "sn", LastName
PutAttrib oUser, "displayName", DisplayName
PutAttrib oUser, "initials", Initials
PutAttrib oUser, "description", Description
PutAttrib oUser, "telephoneNumber", TelephoneNumber
PutAttrib oUser, "title", Title
PutAttrib oUser, "Department", Department
If Len(MailNickName) > 0 Then
PutAttrib oUser, "mail", Mail
PutAttrib oUser, "mailNickName", MailNickName
End If
PutAttrib oUser, "Name", Name
PutAttrib oUser, "LoginScript", LoginScript
'PutAttrib oUser, "ScriptPath", ScriptPath
If (UserType And DesktopUser) = DesktopUser Then
PutAttrib oUser, "HomeDirectory", HomeDirectory
PutAttrib oUser, "homeDrive", HomeDrive
PutAttrib oUser, "ProfilePath", ProfilePath
End If
oUser.SetInfo
'Set oUser = GetObject("WinNT://<DOMAIN>/" & samAccountName & ",user")
oUser.SetPassword (Password)
oUser.AccountDisabled = False
If CreateMailbox Then
Set oMailbox = oUser
'Create a mailbox for the recipient
'You cannot create a mailbox using ADSI, so use CDOEXM
'These values will differ for other organizations
'oMailbox.CreateMailbox "LDAP://" & DCServer & _
"/CN=Mailbox Store (" & _
DCServer & _
"),CN=First Storage Group,CN=InformationStore,CN=" & _
DCServer & _
",CN=Servers,CN=xxxx," & _
"CN=xxx,CN=xx," & _
"CN=Microsoft Exchange,CN=Services," & _
"CN=Configuration," & GetSingleXMLVar("DomainDN")
'oMailbox.CreateMailbox "LDAP://" + "SHFDK01" + _
"/CN=Private Information Store (SHFDK05)" + _
",CN=First Storage Group,CN=InformationStore,CN=" + _
"<EXCHANGESERVER>" & _
",CN=Servers,CN=xxxx," & _
"CN=xxxxxx,CN=xxx," & _
"CN=Microsoft Exchange,CN=Services," & _
"CN=Configuration," & "DC=xxxxxxxx,DC=xxx"
oMailbox.CreateMailbox GetSingleXMLVar("MailStore")
'CreateADSImailbox
End If
oUser.SetInfo
If (UserType And TSUser) = TSUser Then
SetAllowLogonTerminalServer CStr(samAccountName), GetSingleXMLVar("Domain"), True
SetTerminalServerProfilePath CStr(samAccountName), GetSingleXMLVar("Domain"), CStr(ProfilePath)
SetTerminalServerHomeDirDrive CStr(samAccountName), GetSingleXMLVar("Domain"), CStr(HomeDrive)
SetTerminalServerHomeDir CStr(samAccountName), GetSingleXMLVar("Domain"), CStr(HomeDirectory)
Else
SetAllowLogonTerminalServer CStr(samAccountName), GetSingleXMLVar("Domain"), False
End If
Set oUser = Nothing
End Sub
Private Sub PutAttrib(ByRef oUser As IADsUser, sAttrib As String, vParameter)
If Not IsEmpty(vParameter) Then
If Len(vParameter) > 0 Then Call oUser.Put(sAttrib, vParameter)
End If
End Sub
Sub CDOCreateMailBoxRecipient(ServerName As String, _
domainname As String, _
emailname As String, _
FirstName As String, _
LastName As String)
'Dim objPerson As New CDO.Person
Dim objMailbox As CDOEXM.IMailboxStore
objPerson.FirstName = FirstName
objPerson.LastName = LastName
objPerson.Fields("userPrincipalName") = LastName
objPerson.Fields("userAccountControl") = 512
objPerson.Fields("userPassword") = "password"
objPerson.Fields.Update
objPerson.DataSource.SaveTo "LDAP://" + ServerName + _
"/CN=" + emailname + _
",CN=users," + domainname
Set objMailbox = objPerson
tempstr = "LDAP://" + ServerName + _
"/CN=newmailboxstore" + _
",CN=First Storage Group,CN=InformationStore,CN=" + _
ServerName + _
",CN=Servers,CN=First Administrative Group," + _
"CN=Administrative Groups,CN=First Organization," + _
"CN=Microsoft Exchange,CN=Services," + _
"CN=Configuration," + domainname
objMailbox.CreateMailbox tempstr
objPerson.DataSource.Save
End Sub
Private Sub CreateADSImailbox()
'--------------------------------------------------------
' Security object for SD manipulation
' (REQUIRED ADSI TOOL KIT - REGSVR32 ADSSECURITY.DLL)
'---------------------------------------------------------
Dim sid As New ADsSID 'You can also use -- Set sid = CreateObject("ADsSID") for late binding
Dim sec As New ADsSecurity 'You can also use -- Set sec = CreateObject("ADsSecurity") for late binding
'-------------------------------------
' The rest uses ADSI Interfaces
'-------------------------------------
Dim sd As IADsSecurityDescriptor
Dim dacl As IADsAccessControlList
Dim ace As New AccessControlEntry
'-------------------------------------------------------------------------
' If you don't include the ADSI Security Type Library as you make references,
' you must manually declare the following constants.
'-------------------------------------------------------------------------
Const ADS_SID_HEXSTRING = 1
Const ADS_SID_WINNT_PATH = 5
Const ADS_RIGHT_EXCH_MODIFY_USER_ATT = &H2
Const ADS_RIGHT_EXCH_MAIL_SEND_AS = &H8
Const ADS_RIGHT_EXCH_MAIL_RECEIVE_AS = &H10
'--------------------------------------------------------
'---------------CREATING A MAILBOX ----------------------
'--------------------------------------------------------
'--- Server, Org and Site information ---
server = "xxxxx"
Org = "xxxx"
Site = "xxxx"
Domain = "xxxx"
'--- MailBox Parameters ---
strAlias = samAccountName
strMTA = "cn=Microsoft MTA,cn=" & server & ",cn=Servers,cn=Configuration,ou=" & Site & ",o=" & Org
strMDB = "cn=Microsoft Private MDB,cn=" & server & ",cn=Servers,cn=Configuration,ou=" & Site & ",o=" & Org
'--- Creating a user to be associated with the mailbox---
'Set dom = GetObject("WinNT://" & Domain)
'Set usr = dom.Create("user", samAccountName)
'usr.SetInfo
'usr.SetPassword Password
'---------------------------------------------------------------
' Build Recipient container's adsPath:
' LDAP://myserver/CN=Recipients, OU=Site, O=Org
'---------------------------------------------------------------
ADsPath = "LDAP://" + server
ADsPath = ADsPath + "/cn=Recipients,OU="
ADsPath = ADsPath + Site
ADsPath = ADsPath + ",O="
ADsPath = ADsPath + Org
Set objCont = GetObject(ADsPath)
'---Create a new MailBox---
Set Mailbox = objCont.Create("organizationalPerson", "cn=" & strAlias)
Mailbox.Put "mailPreferenceOption", 0
Mailbox.Put "givenName", FirstName
Mailbox.Put "sn", LastName
Mailbox.Put "cn", DisplayName
Mailbox.Put "uid", strAlias
Mailbox.Put "Home-MTA", strMTA
Mailbox.Put "Home-MDB", strMDB
Mailbox.Put "mail", Mail
Mailbox.Put "MAPI-Recipient", True
Mailbox.Put "TextEncodedORaddress", "c=" & "nl" & ";a= " & ";p=" & Org & ";o=" & Site & ";s=" & LastName & ";g=" & FirstName & ";i=" & Initials & ";"
Mailbox.Put "rfc822Mailbox", Mail
'--------------------------------------------------------
' Associating to a primary account
' (Requires the ADSI tool kit - REGSVR32 ADSSECURITY.DLL )
'--------------------------------------------------------
sid.SetAs ADS_SID_WINNT_PATH, "WinNT://" & Domain & "/" & strAlias & ",user"
sidHex = sid.GetAs(ADS_SID_HEXSTRING)
Mailbox.Put "Assoc-NT-Account", sidHex
' Commit the property cache to the directory service
Mailbox.SetInfo
'-------------------------------------------------
' Set the mailbox security
' to allow the user to modify a user attribute,
' send mail, and receive mail
'-------------------------------------------------
Set sd = sec.GetSecurityDescriptor(Mailbox.ADsPath)
Set dacl = sd.DiscretionaryAcl
ace.Trustee = Domain & "\" & strAlias
ace.AccessMask = ADS_RIGHT_EXCH_MODIFY_USER_ATT Or ADS_RIGHT_EXCH_MAIL_SEND_AS Or ADS_RIGHT_EXCH_MAIL_RECEIVE_AS
ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED
dacl.AddAce ace
sd.DiscretionaryAcl = dacl
sec.SetSecurityDescriptor sd
End Sub
<snip>
|
|
|
|
|
Geoff,
I found a solution for you.
Go to this site : http://blogs.msdn.com/exchange/archive/2004/08/04/208045.aspx
You will need the dot.net framework on your computer.
I tried it and it is a fantastic tool.
It even keeps undo information in a XML file.
I'm confident that you can solve your problem with this.
Kind Regards
Peter Verijke
|
|
|
|
|
I have use your script for displaying information about user's mailboxe and it works great. Now I would like to modify the content of some fields.
i.e. Changing the title
How do I do that ?
What I am trying to achieve here is a vb that will create a csv file containing few informations required for our employee's Oracle database and Oracle will supply me with a csv file containing the current and valid employee's informations that I need to upload into Exchange so the employee's information in Exchange is the same as the employee's record (i.e. tel #, address, postal code so on)
|
|
|
|
|
|
Once you verify if a person has an exchange mailbox, how would you query to get the Exchange Server Name.
Using the Outlook client I could get this info as follows:Tools-Options-Mail Setup-Email Accounts - View or Change existing e-mail accounts-Change, the exchange server name is listed.
Any help would be appreciated. TIA
|
|
|
|
|
Hi, nice article. I have been looking for ages on stuff to do with exchange. One question I must ask, is do you know of anyway to connect to exchange to retrieve a users mail?
|
|
|
|
|
Hi,
Yes, I know how to do this.
the easy way is to use pop3, but you have to have Pop3 enabled on the exchange server then.
Can you let me know what your intention is.
Do you need to read the mail in a batch (command) file, or with a vb program?
Regards
Peter
|
|
|
|
|
Hi. What I want to do, is to see if I can create my own mail client (like outlook). I am new to this, so wanted an interesting challenge. We use exchange server (2000) at work, and use the outlook web client. I wanted to create my own version of this, that would be quicker.
I will probably do this using C#, but I can translate the VB.
|
|
|
|
|
There are many sample sources available.
I wrote one a while ago in access, but you better go for a .net example.
I also wrote a mail send class to use as a listener in vb.net.
If you really can't find anything, come back to me then.
Kind Regards
Peter Verijke
|
|
|
|
|
I have to process about 1500 emails/day within a Exchange mailbox. My company does not allow POP3 or IMAP access to Exchange. Could you point me in the right direction on how I can read emails from a exchange mailbox by subject without using POP3 or IMAP. I would like to use VBScript or vb.net if possible. I can't seem to find any examples on how to do this...
Ted
|
|
|
|
|
Do you know wow I query the Active Directory to get the message in the inbox? I'd like to list them in a listbox and then perform an action by double clicking on a line.
|
|
|
|
|
You cannot get the mail messages through AD.
The directory only contains Directory Information like account, name, telephone, etc...
Also maybe some information for 3th party software who extends the AD Scheme like Exchange.
The mail messages retrieved with pop3.
There are many examples of this available on the web.
The Pop3 protocol allowes you to get a list with titles (one by one) without reading the complete e-mail. That would be the best way to go.
Kind Regards
Peter Verijke
|
|
|
|
|