Group Scripts
How to Resolve a Group Name Against a Table in a SQL database
-
Usage: Group loading
-
Description: Connect to a database and resolve a group
Resolve a Group Name
Copy
dim gid as string = HOST.GetSystemName()
Dim sqlConn As new SqlClient.SqlConnection
sqlConn.ConnectionString = "" 'put your connection string here.
sqlConn.Open()
Try
Dim comd As New SqlClient.SqlCommand()
comd.Connection = sqlConn
comd.CommandType = CommandType.Text
comd.CommandTimeout = 1000
comd.CommandText = "select ntcredential from sctmfastconnevtion where DCTMCredentialLoginName ='" + gid.replace("'","''") + "'"Dim rs As SqlClient.SqlDataReader = comd.ExecuteReader()
If (rs.Read()) Then
dim cred as string = HOST.MyToString(rs("ntcredential"))
if cred <> "" then HOST.SetADID(cred)
End If
rs.Close()
Catch ex As Exception
HOST.WriteTrace("Exception:" + ex.message)
end try
sqlConn.close()
return true
How to Load a Static Group From a Static File
-
Usage: Group loading
-
Description: Replace the file name with your file path user
name=ADAccount name2=ADAccount2
for file syntax
Load a Static Group
Copy
Dim FILEPATH As String = "\\server\path\file.txt"Dim groupname As String = HOST.GetSystemName().tolower()
Static lookup As Hashtable = Hashtable.Synchronized(New Hashtable())
if host.getcount() = 1 then lookup.clear()
If lookup.Count = 0 Then
Dim contents() As String = System.IO.File.ReadAllLines(FILEPATH)
For i As Integer = 0 To contents.Length - 1
If Not contents(i).Contains("=") Then Continue For
Dim pair() As String = contents(i).Split("=")
lookup(pair(0).ToLower()) = pair(1)
Next
End If
If lookup.ContainsKey(groupname) andalso HOST.TestADExists(lookup(groupname).tostring()) Then
HOST.SetADID(lookup(groupname).tostring())
End If
End If
Return True