Script to retrive exchange server name
Does anyone have a script or an idea about how to get the exchage server name from Active directory for a user currently logged on?
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
Byoung4now
18 years ago
Try this. It's a little more than you asked for but maybe someone else can use it.
Replace EditHere with samAccount Info. And replace YourCompany with the correct dc= info for your company.
On Error Resume Next
UserNumber = "EditHere"
Set RS = CreateObject("ADODB.Recordset")
RS.open "<LDAP://cn=users,dc=YourCompany,dc=com>;(&(ObjectClass=User)(samAccountName=" & UserNumber & "));adspath;subTree", "provider =ADsDSOObject"
Set User = GetObject(RS.fields("adspath"))
Wscript.echo "Properties For :" & User.FullName&" "
Wscript.echo "CN for : " & User.Name&" "
Wscript.echo "FullName "& User.FullName&" "
Wscript.echo "FirstName "& User.FirstName&" "
Wscript.echo "LastName "& User.LastName&" "
Wscript.echo "EmailAddress "& User.EmailAddress&" "
Wscript.echo "TelephoneMobile "& User.TelephoneMobile&" "
Wscript.echo "TelephoneNumber "& User.TelephoneNumber&" "
Wscript.echo "TelephonePager "& User.TelephonePager&" "
Wscript.echo "FaxNumber "& User.FaxNumber&" "
Wscript.echo "OfficeLocations "& User.OfficeLocations&" "
Wscript.echo "Division "& User.Division&" "
Wscript.echo "Department "& User.Department&" "
Wscript.echo "Description "& User.Description&" "
Wscript.echo "Exchange Server "& User.msExchHomeServerName&" "
Wscript.echo "Manager "& User.Manager&" "
Wscript.echo "Title "& User.Title&" "
Wscript.echo "EmployeeID "& User.EmployeeID&" "
Wscript.echo "HomeDirectory "& User.HomeDirectory&" "
Wscript.echo "LastLogin "& User.LastLogin&" "
Wscript.echo "LastLogoff "& User.LastLogoff&" "
Wscript.echo "LoginScript "& User.LoginScript&" "
Wscript.echo "OtherName "& User.OtherName&" "
Wscript.echo "PasswordLastChanged "& User.PasswordLastChanged&" "
Wscript.echo "Profile "& User.Profile&" "
Wscript.echo "LastFailedLogin "& User.LastFailedLogin&" "
Wscript.echo "AccountDisabled "& User.AccountDisabled&" "
Wscript.echo "IsAccountLocked "& User.IsAccountLocked&" "
Wscript.echo "AccountExpirationDate "& User.AccountExpirationDate&" "
Wscript.echo "BadLoginCount "& User.BadLoginCount&" "
rs.close
Replace EditHere with samAccount Info. And replace YourCompany with the correct dc= info for your company.
On Error Resume Next
UserNumber = "EditHere"
Set RS = CreateObject("ADODB.Recordset")
RS.open "<LDAP://cn=users,dc=YourCompany,dc=com>;(&(ObjectClass=User)(samAccountName=" & UserNumber & "));adspath;subTree", "provider =ADsDSOObject"
Set User = GetObject(RS.fields("adspath"))
Wscript.echo "Properties For :" & User.FullName&" "
Wscript.echo "CN for : " & User.Name&" "
Wscript.echo "FullName "& User.FullName&" "
Wscript.echo "FirstName "& User.FirstName&" "
Wscript.echo "LastName "& User.LastName&" "
Wscript.echo "EmailAddress "& User.EmailAddress&" "
Wscript.echo "TelephoneMobile "& User.TelephoneMobile&" "
Wscript.echo "TelephoneNumber "& User.TelephoneNumber&" "
Wscript.echo "TelephonePager "& User.TelephonePager&" "
Wscript.echo "FaxNumber "& User.FaxNumber&" "
Wscript.echo "OfficeLocations "& User.OfficeLocations&" "
Wscript.echo "Division "& User.Division&" "
Wscript.echo "Department "& User.Department&" "
Wscript.echo "Description "& User.Description&" "
Wscript.echo "Exchange Server "& User.msExchHomeServerName&" "
Wscript.echo "Manager "& User.Manager&" "
Wscript.echo "Title "& User.Title&" "
Wscript.echo "EmployeeID "& User.EmployeeID&" "
Wscript.echo "HomeDirectory "& User.HomeDirectory&" "
Wscript.echo "LastLogin "& User.LastLogin&" "
Wscript.echo "LastLogoff "& User.LastLogoff&" "
Wscript.echo "LoginScript "& User.LoginScript&" "
Wscript.echo "OtherName "& User.OtherName&" "
Wscript.echo "PasswordLastChanged "& User.PasswordLastChanged&" "
Wscript.echo "Profile "& User.Profile&" "
Wscript.echo "LastFailedLogin "& User.LastFailedLogin&" "
Wscript.echo "AccountDisabled "& User.AccountDisabled&" "
Wscript.echo "IsAccountLocked "& User.IsAccountLocked&" "
Wscript.echo "AccountExpirationDate "& User.AccountExpirationDate&" "
Wscript.echo "BadLoginCount "& User.BadLoginCount&" "
rs.close
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.