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!”

24 January, 2011 at 11:54 am Leave a comment

[VB] List all active users in OU whose displayName is different to CN (pre: have OU and domain name)

Click here: Googledoc

21 January, 2011 at 9:29 am Leave a comment

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

20 January, 2011 at 9:27 am Leave a comment

[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,..))

*** Script ***

Thanks for all the subs & functions by others! What will I do without google.

14 January, 2011 at 10:46 am Leave a comment

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)

What I did: copy those 2 above, edit here and there. Now: drop down list having all groups -> pick one group -> list all users and groups in 1 excel file (Name, ID, Department, Type (User/Group), Email).

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:

(1) DocumentGroups.vbs by Richard L. Mueller: Outputs group name, type of group, all members, and types of member, Lists all groups that are members, but does not list the nested group membership. Run at cmd.

(2) Mr Robeto Group Editor: Soft that lists all groups, then all members (users/groups) of a chosen group

(3) WiseSoft_Groups_And_Group_Members_Report.csv: Lists all groups and members (user/group) into excel, with other info (“””Group Type””,””Group””,””Group Path””,””Member Type””,””Member””,””Member Path”””)

5 January, 2011 at 9:00 pm Leave a comment

Older Posts Newer Posts


January 2026
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031