Posts filed under ‘IT/Soft’
VBS – Read txt file and delete duplicated lines
‘READ TXT FILE
‘CREATE A NEW TXT FILE WITH NOON-DUPLICATED ENTRIES
‘EXTRACT SERVER NAMES
strFile = InputBox( “Enter file path, eg D:\all_unix” )
If strFile = “” Then
WScript.Echo “Script quitting.”
WScript.Quit
End If
Dim objFSO: Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Dim dicSort: Set dicSort = CreateObject(“Scripting.Dictionary”)
If objFSO.FileExists(strFile & “.txt”) Then
Dim objFile: Set objFile = objFSO.OpenTextFile(strFile & “.txt”)
‘check and delete all duplicated entries============
Do While Not objFile.AtEndOfStream
On Error Resume Next
strData = objFile.ReadLine
dicSort.Add strData, dicSort.Count
Loop
‘===================================================
objFile.Close
‘create output file
Set objFile = objFSO.CreateTextFile(strFile & “_ServerNameOnly.txt”)
‘go through non-duplicated file, get server name only =================
For Each Item In dicSort
find_Primary = InStr(Item, “Primary:”)
find_NT = InStr(Item, “:NT”)
find_KUX = InStr(Item, “:KUX”)
‘if line has Primary:
If (find_Primary <> 0) Then
objFile.WriteLine (Mid (Item, 9, (find_NT – 9) ) )
End If
‘if line has :KUX
If (find_KUX <> 0) Then
objFile.WriteLine (Left (Item, (find_KUX – 1) ) )
End If
Next
‘=======================================================================
objFile.Close
Else
WScript.Echo “Cannot find file. Script quitting.”
WScript.Quit
End If
Set objFile = Nothing
Set objFSO=Nothing
WScript.Echo “Finish!”
[VB] List all active users in OU whose displayName is different to CN (pre: have OU and domain name)
VBS List all groups in domain
‘=====================================
‘list all groups in domain
‘to run: cscript name.vbs > outputName.txt
‘i copy from somewhere, it works beautifully
‘=====================================
On Error Resume Next
Dim objConnection, objCommand, objRootDSE, strDNSDomain
Dim strFilter, strQuery, objRecordSet, gt
Set objConnection = CreateObject(“ADODB.Connection”)
Set objCommand = CreateObject(“ADODB.Command”)
objConnection.Provider = “ADsDSOOBject”
objConnection.Open “Active Directory Provider”
Set objCommand.ActiveConnection = objConnection
Set objRootDSE = GetObject(“LDAP://RootDSE”)
‘Get domain
strDNSDomain = objRootDSE.Get(“defaultNamingContext”)
strBase = “<LDAP://” & strDNSDomain & “>”
‘Define the filter elements
strFilter = “(&(objectCategory=group))”
‘List all attributes you will require
strAttributes = “displayName,sAMAccountName,groupType”
‘compose query
strQuery = strBase & “;” & strFilter & “;” & strAttributes & “;subtree”
objCommand.CommandText = strQuery
objCommand.Properties(“Page Size”) = 99999
objCommand.Properties(“Timeout”) = 300
objCommand.Properties(“Cache Results”) = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields(“displayName”)
strSA = objRecordSet.Fields(“sAMAccountName”)
gt = objRecordSet.Fields(“groupType”)
if (gt And &h01) <> 0 Then
Scope = “Built-in”
Elseif (gt And &h02) <> 0 Then
Scope = “Global”
Elseif (gt And &h04) <> 0 Then
Scope = “Domain Local”
Elseif(gt And &h08) <> 0 Then
Scope = “Universal”
End If
If (gt And &h80000000) <> 0 Then
SecDst = “Security”
Else
SecDst = “Distribution”
End If
Wscript.Echo Scope & vbTab & SecDst & vbTab & strDN & vbTab & strSA
objRecordSet.MoveNext
Loop
‘ Clean up.
objConnection.Close
Set objConnection = Nothing
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing
[VBA] Count number of files (filtered by time created & type)
Pre: have a text string of folders, separeted by “;” (d:\log1; d:\log2)
Post: go through each folder, count & report number of files in each, filtered by time created (created within 5/10.. mins/hours since now) and type (txt, docs,..))
Thanks for all the subs & functions by others! What will I do without google.
VBA script to list users/groups in AD
Script 1: Drop down list having all groups -> Pick one group -> List all users (Con: skip groups)
Script 2: Enter group name -> List all users/groups (Con: have to enter group name)
Not known if it’s correct :D. And there are bugs. Anyway I’m happy today hic hic. Many thanks to those who wrote (1) and (2).
More reference: