Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Powershell Script Help

Powershell Script Help

Powershell Script Help

Hello Powershell Masters,

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


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
	end If

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


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"

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

MsgBox "Script Completed" 

RE: Powershell Script Help

You'd be better off explaining what you're trying to do.

Do you have your Tek-Tips.com Swag? I've got mine!

Stop by the new Tek-Tips group at LinkedIn.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close