Converting LDAP VBscript to VB.Net

esnmb

Member
Joined
Jul 12, 2005
Messages
15
Programming Experience
Beginner
I can't figure this one out. Here is the script:

VB.NET:
Set objDataList = CreateObject("ADODB.RecordSet")
objDataList.Fields.Append "Count", adVarChar, MaxCharacters
objDataList.Fields.Append "LDAP", adVarChar, MaxCharacters
objDataList.Open
 
objDataList.AddNew
objDataList("Count") = COUNT
objDataList("LDAP") = LDAP
objDataList.Update
 
objDataList.Sort = "Count ASC"
objDataList.MoveFirst
COUNT and LDAP are derived from a WMI query to Exchange.
There is no excel or sql database, this is just created in memory for sorting purposes.

The entire .Net code without the WMI class is below:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] storeResults [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] arrComputers() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = {"mln-exch1", "mln-exch2"}[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Server [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Table1 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataTable[/SIZE]
[SIZE=2]Table1 = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataTable("Exchange")[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Count [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataColumn = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataColumn("Count")[/SIZE]
[SIZE=2]Table1.Columns.Add(Count)[/SIZE]
[SIZE=2]Count.DataType = System.Type.GetType("System.String")[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] LDAP [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataColumn = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataColumn("LDAP")[/SIZE]
[SIZE=2]Table1.Columns.Add(LDAP)[/SIZE]
[SIZE=2]LDAP.DataType = System.Type.GetType("System.String")[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Row1 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataRow[/SIZE]
[SIZE=2]Row1 = Table1.NewRow()[/SIZE]
[SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] Server [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] arrComputers[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myConn [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] ConnectionTester[/SIZE]
[SIZE=2]myConn.ServerName = Server[/SIZE]
[SIZE=2]myConn.Poll()[/SIZE]
[SIZE=2][COLOR=#008000]'* Create storage for the query result[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] WmiQueryResult [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Management.ManagementObjectCollection[/SIZE]
[SIZE=2][COLOR=#008000]'* Retrieve WMI-objects of processes running on target[/COLOR][/SIZE]
[SIZE=2]WmiQueryResult = myConn.ExecWmiQuery("Select * From Exchange_Mailbox")[/SIZE]
[SIZE=2][COLOR=#008000]'* List returned process-names[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] WmiObject [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Management.ManagementObject[/SIZE]
[SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] WmiObject [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] WmiQueryResult[/SIZE]
[SIZE=2]Row1.Item("Count") = WmiObject.GetPropertyValue("ServerName")[/SIZE]
[SIZE=2]Row1.Item("LDAP") = WmiObject.GetPropertyValue("StoreName")[/SIZE]
[SIZE=2]Row1 = Table1.NewRow()[/SIZE]
[SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
I also would need to figure out how to retrieve the data after sorting it by count.
 
Last edited by a moderator:
Back
Top