JSI Tip 10216. How can a script return computer properties using the WinNT provider?


ComputerProp.vbs is a sample script that will returns a computer's properties in aligned columns.

The syntax for using the ComputerProp.vbs script is:

CScript.exe //nologo <Drive:>\<FolderName>\ComputerProp.vbs <ComputerName>

Examples:

When I run:

cscript //nologo c:\util\ComputerProp.vbs JSI001

I receive:

Computer | Division  | Owner           | OperatingSystem | OperatingSystemVersion | Processor                       | ProcessorCount
JSI001   | JSI, Inc. | Jerold Schulman | Windows NT      | 5.2                    | x86 Family 6 Model 7 Stepping 3 | Multiprocessor Free
When I run:

cscript //nologo c:\util\ComputerProp.vbs JSI009

I receive:

Computer | Division  | Owner           | OperatingSystem | OperatingSystemVersion | Processor                        | ProcessorCount
JSI009   | JSI, Inc. | Jerold Schulman | Windows NT      | 5.1                    | x86 Family 15 Model 2 Stepping 7 | Multiprocessor Free
ComputerProp.vbs contains:
Dim objArguments, strComputer, out
Set objArguments = Wscript.Arguments
If WScript.Arguments.Count = 0 then Wscript.Quit
strComputer=objArguments(0)
On Error Resume Next 
Set objComputer = GetObject("WinNT://" & strComputer ) 
out = "Computer|Division|Owner|OperatingSystem|OperatingSystemVersion|Processor|ProcessorCount" & vbCrLf
out = out & strComputer & "|" _
 & objComputer.Division & "|" _
 & objComputer.Owner & "|" _
 & objComputer.OperatingSystem & "|" _
 & objComputer.OperatingSystemVersion & "|" _
 & objComputer.Processor & "|" _
 & objComputer.ProcessorCount
Wscript.Echo Make_Columns(out, "|", " ")
Wscript.Quit

Function Make_Columns(stringTEXT, deMark, leadTrailSpace)
Dim arrayCOL, elementCOL, strElement, elementROW
Dim arrayLEN, elementLEN, arrayROW, stringROW
Dim stringProportional, proportionalColumns, number
Make_Columns = ""
proportionalColumns = ""
'Set each column widths to widest value.
    arrayROW = Split(stringTEXT,vbCrLf)
    For elementROW = 0 To UBound(arrayROW)
        stringROW = arrayROW(elementROW)
        arrayCOL = Split(stringROW,deMark)
        If elementROW = 0 Then
            ReDim arrayLEN(UBound(arrayCOL))
            For elementLEN = 0 To UBound(arrayLEN)
                arrayLEN(elementLEN) = 0
            Next
        End If
        For elementCOL = 0 To UBound(arrayCOL)
            strElement = Trim(arrayCOL(elementCOL))
            If Len(strElement) > arrayLEN(elementCOL) Then
                arrayLEN(elementCOL) = Len(strElement)
            End If
        Next
    Next
'Execute spacing.
    For elementROW = 0 To UBound(arrayROW)
        stringROW = arrayROW(elementROW)
        arrayCOL = Split(stringROW,"|")
        For elementCOL = 0 To UBound(arrayCOL)
            strElement = Trim(arrayCOL(elementCOL))
            number = arrayLEN(elementCOL) - Len(strElement)    
            stringProportional = Space(number)
            If elementCOL = 0 Then 
                proportionalColumns = proportionalColumns & strElement & stringProportional
            Else
                proportionalColumns = proportionalColumns & leadTrailSpace & deMark & leadTrailSpace & strElement & stringProportional
            End If
        Next
        proportionalColumns = proportionalColumns & vbCrLf
    Next
    Make_Columns = proportionalColumns
End Function
NOTE: FYI How can I display a file of information in aligned columns?



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish