Powershell SCCM and Importing a driver from INF

rated by 0 users
This post has 0 Replies | 1 Follower

Not Ranked
Posts 1
killragtshirts Posted: 08-11-2011 3:16 AM

Hi,

Sorry about the length of this post.

I have posted this on numerous forums without reply. So hopefully someone could please help me as I have been trying to crack this nut for two weeks. The SCCM SDK mentions that it is possible to import a driver into SCCM from a INF file. I have tested this using VBscript and it does indeed work. I'm trying to convert the VBscript to powershell. THe vbscript code is here:

=========================================

Sub ImportINFDriver(connection, path, name)

    Dim driverClass
    Dim inParams
    Dim outParams
    
    On Error Resume Next
    
    ' Obtain an instance of the class 
    ' using a key property value.

    Set driverClass = connection.Get("SMS_Driver")

    ' Obtain an InParameters object specific
    ' to the method.
    Set inParams = driverClass.Methods_("CreateFromINF"). _
        inParameters.SpawnInstance_()

    ' Add the input parameters.
    inParams.Properties_.Item("DriverPath") =  path
    inParams.Properties_.Item("INFFile") =  name

    ' Call the method.
    ' The OutParameters object in outParams
    ' is created by the provider.
    Set outParams = connection.ExecMethod("SMS_Driver", "CreateFromINF", inParams)

   If Err <> 0 Then
        Wscript.Echo "Failed to add to the driver catalog: " + path + "\" + name
        Exit Sub
    End If    
                
    outParams.Driver.IsEnabled =  True
          
    Dim LocalizedSettings(0)
    Set LocalizedSettings(0) = connection.Get("SMS_CI_LocalizedProperties").SpawnInstance_()
    LocalizedSettings(0).Properties_.item("LocaleID") =  1033 
    LocalizedSettings(0).Properties_.item("DisplayName") = _
            GetDriverName(outParams.Driver.SDMPackageXML, "//DisplayName", "Text")

    LocalizedSettings(0).Properties_.item("Description") = ""        
    outParams.Driver.LocalizedInformation = LocalizedSettings

    ' Save the driver.
    outParams.Driver.Put_
     
End Sub

Function GetDriverName(xmlContent, nodeName, attributeName)
    ' Load the XML Document
    Dim attrValue
    Dim XMLDoc
    Dim objNode
    Dim displayNameNode
    
    attrValue = ""
    Set XMLDoc = CreateObject("Microsoft.XMLDOM")     
    XMLDoc.async = False
    XMLDoc.loadXML(xmlContent)
    
    'Check for a successful load of the XML Document.
    If xmlDoc.parseError.errorCode <> 0 Then
        WScript.Echo vbcrlf & "Error loading XML Document. Error Code : 0x" & hex(xmldoc.parseerror.errorcode)
        WScript.Echo "Reason: " & xmldoc.parseerror.reason
        WScript.Echo "Parse Error line " & xmldoc.parseError.line & ", character " & _
                      xmldoc.parseError.linePos & vbCrLf & xmldoc.parseError.srcText
    
        GetXMLAttributeValue = ""        
    Else
        ' Select the node
        Set objNode = xmlDoc.SelectSingleNode(nodeName)
        
        If Not objNode Is Nothing Then
            ' Found the element, now just pick up the Text attribute value
            Set displayNameNode = objNode.attributes.getNamedItem(attributeName)
            If Not displayNameNode Is Nothing Then
               attrValue = displayNameNode.value
            Else
               WScript.Echo "Attribute not found"
            End If
        Else
            WScript.Echo "Failed to locate " & nodeName & " element."
        End If
    End If
    
    ' Save the results
    GetDriverName = attrValue
End Function
========================================================

This is the powershell script I have.

========================================================
$SiteServer = "xxxxxxx"
$smsNamespace = "root\sms\site_xxx"
$DriverClass = "SMS_Driver"
$infMethod = "CreateFromINF"
$infFileName = "TPLCD.INF"
$infFilePath = "\\xxxxxxx\e$\+Dev\DriversToInject\test"

#Set up a connection to the SMS Provider.
$swbemLocator = New-Object -com "WbemScripting.SWbemLocator"
$swbemLocator.Security_.AuthenticationLevel = 6
$Connection = $swbemLocator.ConnectServer($SiteServer, $smsNamespace)

#Obtain an instance of the class using a key property value.
$DriverClass = $connection.Get("SMS_Driver")

#Obtain an InParameters object specific to the method.
$Inparams = $DriverClass.Methods_.item("CreateFromINF").Inparameters.SpawnInstance_()

#Add the input parameters.
$Inparams.Properties_.item("DriverPath").value = $infFilePath
$Inparams.Properties_.item("INFFile").value = $infFileName

#Execute the method. Out Parameter is Created.
$Outparams = $DriverClass.ExecMethod_("CreateFromINF",$Inparams)

#Set IsEnabled Property to equal True.
$Outparams.Properties_.item("driver").value.properties_.item("IsEnabled").value = $true

#XML Section
#Get Driver Details from the XML Object created when CreateFromINF method executed.
$xml = $Outparams.Properties_.item("driver").value.properties_.item("SDMPackageXML").value
$xmlObj = New-Object XML
$xmlObj.LoadXml($xml)
$xmlObj.PreserveWhitespace
$LocalizedDisplayName = $xmlObj.DesiredConfigurationDigest.driver.Annotation.DisplayName.text

#Localized Properties Instance.
$LocalProperties = $Connection.Get("SMS_CI_LocalizedProperties").SpawnInstance_()
$LocalProperties.Properties_.item("Description").value = "TestLuke"
$LocalProperties.Properties_.item("DisplayName").value = $LocalizedDisplayName
$LocalProperties.Properties_.item("InformativeURL").value = ""
$LocalProperties.Properties_.item("LocaleID").value = "1033"

[System.Object[]] $LocalArray += $LocalProperties.Properties_

$Outparams.Properties_.item("Driver").value.properties_.item("LocalizedInformation").value = $LocalArray

$Outparams.Properties_.item("Driver").Put_

=========================================================

I get a type error on this line....

$Outparams.Properties_.item("Driver").value.properties_.item("LocalizedInformation").value = $LocalArray
I think the System.__Object format is throwing me a little and I cant seem to get the array right.


Page 1 of 1 (1 items) | RSS
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.