Photo Gallery
Member List
Search
Calendars
FAQ
Ticket List
Log Out
Forums
Register
Login
My Profile
Inbox
Address Book
My Subscription
My Forums
Get Exchange Servers Name
Logged in as: Guest
arrSession:exec spGetSession 2,16,61244
Active Users: There are
0
members and
0
guests.
Users viewing this topic: none
Printable Version
All Forums
>>
[Scripting]
>>
Post a VBScript
>> Get Exchange Servers Name
Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page:
[1]
Login
Message
<< Older Topic
Newer Topic >>
Get Exchange Servers Name -
6/9/2008 10:11:42 PM
4scriptmoni
Posts: 192
Score: 0
Joined: 5/3/2007
Status:
offline
I have many scripts where the user must enter the name of the Exchange server so I came up with a way to automaticly gets it :
'Get the Exchange Server -> only of the User Logged in (Warning: will not get multiple Exchange Servers!) 'Author: Felipe Ferreira 'Date: 06/06/08 'Version: 1.0 Option Explicit Dim username,userdomain,homeServer,homeMDB,cn,USERDN Dim arrhomeS Dim objShell : Set objShell = CreateObject("WScript.Shell") ' Run cmds wscript.echo "EXCHANGE SERVER = " & GetExchangeServer() wscript.quit '@@@@@@@@@@@@@@@@@@@@@@SUBS AND FUCNTIONS@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ function GetExchangeServer() set cn = createobject("adodb.connection") cn.provider = "ADsDSOObject" cn.open getUserInfo USERDN = query("objectClass='user' AND sAMAccountName='" & USERNAME & "'", cn) checkLocalMailbox GetExchangeServer = homeServer end function sub getUserInfo() Dim env : set env = objShell.environment("PROCESS") USERNAME = env("USERNAME") USERDOMAIN = env("USERDOMAIN") if USERDOMAIN = "" then wscript.echo "You Must be in a Domain!" wscript.quit end if end sub sub checkLocalMailbox() homeMDB = getprop(USERDN, "homeMDB") if homeMDB = "" then mailboxContinue homeMDB = getobject("LDAP://" & USERDN).get("homeMDB") homeServer = getobject("LDAP://" & homeMDB).get("msExchOwningServer") if homeServer = "" then Wscript.echo "Could not get the Exchange Server, be sure the user you are login is in a domain and have a Mailbox!" wscript.quit end if arrhomeS = split(homeServer,"CN=") arrhomeS(1) = replace(arrhomeS(1),",","") arrhomeS(1) = trim(arrhomeS(1)) 'wscript.echo "EXCHANGE SERVER : " & arrhomeS(1) homeServer = arrhomeS(1) end sub function query(where_, cn_) Dim rcset_ : set rcset_ = createobject("adodb.recordset") rcset_.open "SELECT distinguishedName FROM 'LDAP://" & USERDOMAIN & "' WHERE " & where_, cn_ if rcset_.recordcount = 0 then quit("Active Directory search failed, so either 1) The specified Workflow Account or Exchange Domain Servers group does not exist. 2) Commonly this is due to replication delays in the Active Directory, in which case you should try again after waiting a reasonable amount of time for your topology.") if rcset_.recordcount > 1 then quit("Unexpected error") query = rcset_.fields("distinguishedName") end function function getprop(dn_, prop_) Dim o,value set o = getobject("LDAP://" & dn_) on error resume next value = o.get(prop_) on error goto 0 if err = 0 then getprop = value end function
But Today I just came along this code witch is much better then mine, because it can get multiple servers.
'Get Exchange Servers 'From Scott Souther (checkqueue.hta) Dim Conn, Com, Rs, IADRootDSE, varConfigNC, strQuery Dim i : i = 0 Dim arrServers(10) Set Conn = createobject("ADODB.Connection") Set com = createobject("ADODB.Command") Set rs = createobject("ADODB.Recordset") ' Get the configuration naming context Set iAdRootDSE = GetObject("LDAP://RootDSE") varConfigNC = iAdRootDSE.Get("configurationNamingContext") ' Open the connection Conn.Provider = "ADsDSOObject" Conn.Open "ADs Provider" ' Build the query to find all Exchange Server computers. strQuery = "<LDAP://" & varConfigNC & ">;(objectCategory=msExchExchangeServer);name,versionnumber;subtree" Com.ActiveConnection = Conn Com.CommandText = strQuery Set Rs = Com.Execute While Not Rs.EOF If rs.fields ("versionnumber") > 4417 then wscript.echo RS.Fields("name") arrServers(i) = RS.Fields("name") i = i + 1 End if rs.movenext Wend
_____________________________
Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net
Post #: 1
If you found our site useful please link to us
<a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>
.
All Forums
>>
[Scripting]
>>
Post a VBScript
>> Get Exchange Servers Name
Page:
[1]
Jump to:
Select a Forum
All Forums
----------------------
[Welcome]
- - Forum Rules
- - Test Posting Messages
- - New Member Area/Introduction
[Scripting]
- - WSH & Client Side VBScript
- - WSH & Client Side VBScript Tutorial
- - Post a VBScript
- - Windows PowerShell
- - ASP
- - ASP.NET
- - Windows Script Components
[General Forum]
- - Other Programming/Scripting Languages
- - Suggestions & Feedback
- - Off-Topic Lounge
New Messages
No New Messages
Hot Topic w/ New Messages
Hot Topic w/o New Messages
Locked w/ New Messages
Locked w/o New Messages
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
Forum Software ©
ASPPlayground.NET
Advanced Edition
2.5.5 ANSI