none
Не возможно прочитать HP Part Number по Active Directory и записать его в файл Excel. RRS feed

  • Общие обсуждения

  • Тут пример сценария, не ясно, может где ошибка.
    Сценарий замечательно отрабатывает по имени компьютеров и серийным номерам, но HP Part Number собирать не хочет.

    '==========================================================================
    '
    ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2007
    '
    ' NAME: Denis
    '
    ' AUTHOR: Morpheus
    ' DATE  : 06.06.2009
    '
    ' COMMENT: Workstations
    '
    '==========================================================================
    Option Explicit
    On Error Resume Next
    '*************************************************************************
    'Reading Serial Numbers from Workstations
    '*************************************************************************
    'Demonstration Script that reads the serial number as reported by Bios
    'There is no limit to the number of items that may be included.
    ' (c) Script by Morpheus
    '*************************************************************************
    '*************************************************************************
    ' Script Name BiosSerialRead.vbs
    ' Script Version 1.0
    ' Script Date: 06.06.09
    ' Script Created by Morpheus
    '*************************************************************************
    '*************************************************************************
    'Object Creation
    '*************************************************************************
    Dim ObjExplorer, ie, objConnection,objCommand, objRecordSet, objPing, objStatus, objXL
    Dim colBIOS, colPN, objPN, objBIOS, objDocument, objWMIService
    Dim ComputerName, strComputer, SerialNumber, ProductNumber, x

    ' '-------------------------------------------------------------------------
    ' ' Creating an Internet Explorer Window to Display Information and provide Error Detection
    ' '-------------------------------------------------------------------------
    ' Set objExplorer = CreateObject("InternetExplorer.Application")
    ' Set ie = wscript.createobject("internetexplorer.application","event_")
    ' ie.navigate("javascript:'<title>Postinstallation-Process running...</title><body scroll=no></body>'")
    ' ie.width = 750
    ' ie.height = 600
    ' ie.toolbar = False
    ' ie.statusbar = False
    ' ie.visible = True
    ' Wscript.Sleep 2000
    '  Do
    '   loop while ie.readystate<>4

    '-------------------------------------------------------------------------
    ' Creating Excel Tabelle to Display Information
    '-------------------------------------------------------------------------
    Set objXL = WScript.CreateObject("Excel.Application")
    objXL.Visible = True
    objXL.WorkBooks.Add
    objXL.Cells(1, 1).Value = "Workstation Name"
    objXL.Cells(1, 2).Value = "Serial Number"
    objXL.Cells(1, 3).Value = "HP Product Number"
    objXL.Cells(1, 4).Value = "Status"
    objXL.Rows("1:1").Select
    objXL.Selection.Font.Bold = True

    '*************************************************************************
    'Get Computer Names from Active Directory
    '*************************************************************************
    Const ADS_SCOPE_SUBTREE = 2
     x=1
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand =   CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection
    objCommand.CommandText = _
        "SELECT Name, Location FROM 'LDAP://OU=Workstations, OU=Auto, DC=AL, DC=LOC' " _
            & "WHERE objectClass='computer'"
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Timeout") = 30
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
    objCommand.Properties("Cache Results") = False
    Set objRecordSet = objCommand.Execute
    objRecordSet.MoveFirst
    Do Until objRecordSet.EOF
      
        ComputerName = objRecordSet.Fields("Name").Value  
      
    '*************************************************************************
    ' Ping Computer before WMI Connection - Error Handling - Query Bios
    '*************************************************************************
    strComputer = ComputerName
    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
    ExecQuery("select * from Win32_PingStatus where address = '"_
    & strComputer & "'")

    For Each objStatus in objPing
    If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
    '------------------------------
    'Function to use for Negative IE Display
    'FailedDisplay
    '------------------------------
    'Function to use for Negative Excel Entry
    WriteExcelFailed
    '------------------------------

    Else
    '-------------------------------------------------------------------------
    'Query PC Name for Serial Number and HP Product Number
    '-------------------------------------------------------------------------
    strComputer = ComputerName
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colBIOS = objWMIService.ExecQuery _
        ("SELECT * FROM Win32_BIOS")
                                    
    For Each objBIOS in colBIOS
         SerialNumber = objBIOS.SerialNumber
         ''Product Number = "objBIOS.SKUNumber"

    '------------------------------
    'Function to use for Positive IE Display
    ' PassedDisplay
    '------------------------------
    'Function to use for Positive Excel Entry
    WriteExcelPassed
    '------------------------------

    Next

    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\HP\InstrumentedBIOS")
    Set colPN = objWMIService.ExecQuery _
        ("SELECT * FROM HP_SMBIOS_SystemInformation") 
        
    For Each objPN in colPN
         ProductNumber = objPN.SKUNumber
    WriteExcelPassed1
    Next
    End If
    Next

    '-------------------------------------------------------------------------
    'Restarts Process until all of AD is read (defined OU only.)
    '-------------------------------------------------------------------------
    objRecordSet.MoveNext
    x = x+1
    Loop
    '------------------------------
    ' Closes Excel File when Process is Finished
    objXL.Save "C:\temp\BiosRead.xls"
    objXL.application.quit
    Set obj.XL = nothing
    '*************************************************************************
    'End of Module
    '*************************************************************************

    '*************************************************************************
    ' Functions / Subs
    '*************************************************************************
    '*************************************************************************
    ' Function for Writing information to a html display window.
    '*************************************************************************
    ' Sub FailedDisplay
    ' Set objDocument = ie.Document
    ' objDocument.Writeln "<html><head><title>Post Installation</title></head>"
    ' objDocument.Writeln "<body bgcolor='yellow'>"
    ' objDocument.Writeln "<br>Workstation Information Retrieved.<br>"
    ' objDocument.Writeln "</body></html>"
    ' objDocument.Writeln "<td width='50%'>" & strComputer & " = PC NOT FOUND",  "</td><BR>"
    ' End Sub

    '*************************************************************************
    ' sub PassedDisplay
    ' Set objDocument = ie.Document
    ' objDocument.Writeln "<html><head><title>Post Installation</title></head>"
    ' objDocument.Writeln "<body bgcolor='yellow'>"
    ' objDocument.Writeln "<br>Workstation Information Retrieved.<br>"
    ' objDocument.Writeln "</body></html>"
    ' objDocument.Writeln "<td width='50%'>" & strComputer & " = " & SerialNumber,  "</td><BR>"
    ' End sub
    '*************************************************************************

    '*************************************************************************
    ' Function WriteExcel (Passed or Failed) for Writing information to an Excel File
    '*************************************************************************
    sub WriteExcelPassed
     objXL.Cells(x+1, 1).Value = strComputer
      objXL.Cells(x+1, 2).Value = SerialNumber
      ''objXL.Cells(x+1, 3).Value = SKUNumber
            objXL.Cells(x+1, 4).Value = " "
    End Sub

    sub WriteExcelPassed1
     objXL.Cells(x+1, 3).Value = ProductNumber
    End Sub

    sub WriteExcelFailed
     objXL.Cells(x+1, 1).Value = strComputer
      objXL.Cells(x+1, 2).Value = " " 
            objXL.Cells(x+1, 3).Value = " "
            objXL.Cells(x+1, 4).Value = "PC Not Found"
    End Sub
    '------------------------------
    'End of Functions and Subs
    '*************************************************************************
    'END OF SCRIPT Checked and approved 06.06.09 - Morpheus
    '*************************************************************************




    denispolunin
    16 июля 2009 г. 7:56