Archive for January, 2011

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

boss talk

Friday night was FT’s BBQ. I had such a memorable talk with Mark Tan.

When he nicely asked me about my school and work assignments,  my replies were similar to these: “I was not trained in anything technical at school; I forget it all already; I don’t have any skill; I didn’t do anything at all during the last few months haha”, etc.

Then when I asked him “Which team are you with”, he said “Your boss reports to me”. Ha. He then said he “would like to have a talk” with me this Tuesday!! Oy…

23 January, 2011 at 5:27 pm Leave a comment

too too

i’m reading “Too soon old, too late smart” and loving it. like this the most out of its 30 ‘life’s simple truths’:

The perfect is the enemy of the good.

and this site has lots of  nice quotes – which i need now.

21 January, 2011 at 1:28 pm 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

Older Posts Newer Posts


January 2011
M T W T F S S
 12
3456789
10111213141516
17181920212223
24252627282930
31