Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Powershell Script Help

Status
Not open for further replies.

Hun9865

Technical User
Oct 23, 2012
23
0
0
GB
Hello Powershell Masters,

I have below script in VBscript, Would like to convert in PowerShell. Kindly help me in this…

Code:
option Explicit

const ForReading = 1, ForWriting = 2, ForAppending = 3

dim arrErrors(13) 'I wanted to check list of errors from my array condition
dim objFSO, objServerList, objErrorLog, strErrorLine, strError, strDate 
dim strComputer, strToday, strFilePath, objCoreApp, strLine, today, i, dDate

set objFSO = CreateObject("Scripting.FileSystemObject")

set objServerList = objFSO.OpenTextFile("list.txt", ForReading) ' Input Servers List

set objErrorLog = objFSO.CreateTextFile("error.log") ' Writing out put directory 

objErrorLog.WriteLine "This Script will check for  below 0 to 13 Errors only"

objErrorLog.WriteLine "0 =  APP0"
objErrorLog.WriteLine "1 =  APP1"
objErrorLog.WriteLine "2 =  APP2"
objErrorLog.WriteLine "3 =  APP3"
objErrorLog.WriteLine "4 =  APP4"
objErrorLog.WriteLine "5 =  APP5"
objErrorLog.WriteLine "6 =  APP6"
objErrorLog.WriteLine "7 =  APP7"
objErrorLog.WriteLine "8 = APP8"
objErrorLog.WriteLine "9 = APP9"
objErrorLog.WriteLine "10 =  APP10"
objErrorLog.WriteLine "11 = APP11"
objErrorLog.WriteLine "12 = APP12"
objErrorLog.WriteLine "13 = APP13"



strToday = right("0" & datePart("m", date()), 2) & "/" & right("0" & datePart("d", date()), 2) & "/" & datePart("yyyy", date()) 

' strtoday = the current date in format for example 12/26/2012
'below are my error text which will be in my d:\log.txt file on every server and want to cath them

arrErrors(0) = "APP0"
arrErrors(1) = "APP1"
arrErrors(2) = "APP2"
arrErrors(3) = "APP3"
arrErrors(4) = "APP4"
arrErrors(5) = "APP5"
arrErrors(6) = "APP6"
arrErrors(7) = "APP7"
arrErrors(8) = "APP8"
arrErrors(9) = "APP9"
arrErrors(10) = "APP10"
arrErrors(11) = "APP11"
arrErrors(12) = "APP12"
arrErrors(13) = "APP13"


On error resume Next

Do while not (objServerList.AtEndOfStream)


strComputer = objServerList.ReadLine

strFilePath = "\\" & strComputer & "\d$\LOG\"

Set objCoreApp = objFSO.OpenTextFile(strFilePath & "log.txt", ForReading)

objErrorLog.WriteLine strComputer & vbTab & "," & vbTab & "Checking the log.txt...."

If Err = 0 Then ' if server has d:\log\log.txt file then continue below DO loop

	Do while not (objCoreApp.AtEndOfStream)
	
	
	strLine = objCoreApp.ReadLine
	
		
	if (left(strLine, len(strToday) + 1) = "[" & strToday) then

'My log.txt file has line as [12/03/2012 hence i am check [ with current date i.e [12/26/2012
'Below is the sample log.txt with current date.
'[12/26/2012 00:19:19:598 ???? INF] {tid=16A4}
'Aplication filter loaded.
'
'Empty space one or two or three lines
'[12/26/2012 00:19:19:598 VSCM INF] {tid=16A4}
'An error occurred while app3

	
	strErrorLine = objCoreApp.ReadLine
	
	for i = 0 to ubound(arrErrors)
	
	strError = arrErrors(i)
	
	if (left(lcase(strErrorLine), len(strError)) = lcase(strError)) then
	
	
	objErrorLog.WriteLine strErrorLine & vbTab & strComputer & vbTab & "Found Error number" & vbTab & i

' this should find from above log "'An error occurred while app3" which is in above sample log text
	
	exit for
	end If
	
	next
	
	end If
	loop
objCoreApp.close

objErrorLog.WriteLine "Completed Checking" & vbTab & strComputer & vbTab & "server"

Else

objErrorLog.WriteLine "Error" & vbTab & strComputer & vbTab & "not able to check the server...Check the Availability of server or are able to open d$\LOG\log.txt"

Err.Clear
End If
loop
objErrorLog.WriteLine "Completed Checking all the servers..Exiting the script...."

objErrorLog.Close
objServerList.Close
MsgBox "Script Completed"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top