Need help fixing vbs script from eventsentry blog. the software raid one

+1 vote
asked Oct 13 in EventSentry by at0mic (190 points)

hi,

i need help fixing a vbs script if anyones good with it. When i run on on a few machines it says "invalid character" when it is tested.

blog:
https://www.eventsentry.com/blog/2012/02/how-to-make-the-windows-softwa.html


‘ Lists all logical drives on the local computer which are configured for
‘ software RAID. Returns an %ERRORLEVEL% of 1 if any redundant drive is
‘ not in a “Healthy” state. Returns 0 otherwise.
‘
‘ Supports Windows Vista/7, Windows 2008/R2

Option Explicit

Dim WshShell, oExec
Dim RegexParse
Dim hasError : hasError = 0

Set WshShell = WScript.CreateObject(“WScript.Shell”)
Set RegexParse = New RegExp

‘ Execute diskpart
Set oExec = WshShell.Exec(“%comspec% /c echo list volume | diskpart.exe”)

RegexParse.Pattern = “\s\s(Volume\s\d)\s+([A-Z])\s+(.*)\s\s(NTFS|FAT)\s+(Mirror|RAID-5)\s+(\d+)\s+(..)\s\s([A-Za-z]*\s?[A-Za-z]*)(\s\s)*.*”

While Not oExec.StdOut.AtEndOfStream
    Dim regexMatches
    Dim Volume, Drive, Description, Redundancy, RaidStatus
    Dim CurrentLine : CurrentLine = oExec.StdOut.ReadLine
    
    Set regexMatches = RegexParse.Execute(CurrentLine)
    If (regexMatches.Count > 0) Then
        Dim match
        Set match = regexMatches(0)
        
        If match.SubMatches.Count >= 8 Then
            Volume      = match.SubMatches(0)
            Drive       = match.SubMatches(1)
            Description = Trim(match.SubMatches(2))
            Redundancy  = match.SubMatches(4)
            RaidStatus  = Trim(match.SubMatches(7))
        End If

        If RaidStatus <> “Healthy” Then
            hasError = 1
            WScript.StdOut.Write “**WARNING** “
        End If
        
        WScript.StdOut.WriteLine “Status of ” & Redundancy & ” ” & Drive & “: (” & Description & “) is “”” & RaidStatus & “”””
    End If
Wend

If (hasError) Then
    WScript.StdOut.WriteLine “”
    WScript.StdOut.WriteLine “WARNING: One or more redundant drives are not in a “”Healthy”” state!”
End If

WScript.Quit(hasError)


 

2 Answers

+1 vote
answered Oct 13 by ryanfitzgerald (730 points)

This looks to be an issue with the formatting of the quotation marks.  The comment character in VBScript is a single quote (') , however in the code included it was displayed as a backtick(`) which is most likely causing the invalid character error. Please try replacing all ` characters with a single quote and “ ” quotes with double quotes. 

Revised code:

' Lists all logical drives on the local computer which are configured for
' software RAID. Returns an %ERRORLEVEL% of 1 if any redundant drive is
' not in a “Healthy” state. Returns 0 otherwise.
'
' Supports Windows Vista/7, Windows 2008/R2

Option Explicit

Dim WshShell, oExec
Dim RegexParse
Dim hasError : hasError = 0

Set WshShell = WScript.CreateObject("WScript.Shell")
Set RegexParse = New RegExp

' Execute diskpart
Set oExec = WshShell.Exec("%comspec% /c echo list volume | diskpart.exe")

RegexParse.Pattern = "\s\s(Volume\s\d)\s+([A-Z])\s+(.*)\s\s(NTFS|FAT)\s+(Mirror|RAID-5)\s+(\d+)\s+(..)\s\s([A-Za-z]*\s?[A-Za-z]*)(\s\s)*.*"

While Not oExec.StdOut.AtEndOfStream
    Dim regexMatches
    Dim Volume, Drive, Description, Redundancy, RaidStatus
    Dim CurrentLine : CurrentLine = oExec.StdOut.ReadLine
    
    Set regexMatches = RegexParse.Execute(CurrentLine)
    If (regexMatches.Count > 0) Then
        Dim match
        Set match = regexMatches(0)
        
        If match.SubMatches.Count >= 8 Then
            Volume      = match.SubMatches(0)
            Drive       = match.SubMatches(1)
            Description = Trim(match.SubMatches(2))
            Redundancy  = match.SubMatches(4)
            RaidStatus  = Trim(match.SubMatches(7))
        End If

        If RaidStatus <> "Healthy" Then
            hasError = 1
            WScript.StdOut.Write "**WARNING** "
        End If
        
        WScript.StdOut.WriteLine "Status of " & Redundancy & " " & Drive & ": (" & Description & ") is """ & RaidStatus & """"
    End If
Wend

If (hasError) Then
    WScript.StdOut.WriteLine ""
    WScript.StdOut.WriteLine "WARNING: One or more redundant drives are not in a ""Healthy"" state!"
End If

WScript.Quit(hasError)

 

+1 vote
answered Oct 13 by at0mic (190 points)
nm. found out all the " were pasting as weird characters and fudging the script. pasted all to notepad2 anyway and fixed the wierd chars in for "

also removed the useless comments like ryan  mentioned. thanks.
Welcome to EventSentry Q&A, where you can ask questions and receive answers from other members of the community.
...