Unfortunately, with today's economy there is less and less of a budget for IT and tools. So we need to look at building a very basic login script to look at a user's local administrator group on their workstation and place the contents of that group into a database. I commented out the first script I came across, I'm just confused on how to pull the data from the workstation and import it into the SQL table.
Yes we run an active directory domain and we would tie this login script to each user's GPO to gather the necessary data so the help desk can see who has local administrator rights on their workstation.
I ran the following and it does sort of what I need, but it gives too much data, it would be cleaner in
VB and writing the data to a SQL database.
---
REM #test.bat
echo %computername% >> C:\test.txt
net localgroup Administrators >> C:\test.tx
----
Function WriteToDatabase(sUserName)
'I see the variable
Dim mConnection
'The connection to the database
Set mConnection = CreateObject("ADODB.Connection")
mConnection.Open "Provider=SQLOLEDB.1;Data Source=myServerName;Initial Catalog=myDatabaseName","myUserName","myPassword"
'This is where i get confused:\ If i can extract the data with a previous script how do i import into into the table?
mConnection.Execute "INSERT INTO tbl_user_log (user_name, login_date) VALUES ('" & sUserName" & ", GetUTCDate())"
Set mConnection = Nothing
End Function
'This will write the username and current GMT date/time to a database table called tbl_user_log, with the fields user_name (VARCHAR) and login_date (DATETIME).
'If you want to retrieve values, use a recordset object such as:
Set mRecordset = CreateObject("ADODB.Recordset")
mRecordset = "your SQL command here", mConnection