none
SCCM Powershell Script Fails Occasionally - Looking for guidance

    Pertanyaan

  • I have the following script that we have been running for a number of months to create a consolidated updatelist from several individual update lists. 

    Suddenly beginning in 2012 we started getting the following errors.  This it may have to do with the size of the update lists.  It works sometime with only three months, but not four.  When using three months, sometimes it takes three times to run, but does run. (Why does it take three times)

    Any assistance on what is causing the issues.

    Conjecture is that it is either a timeout or a size issue.

    Errors:

    The following error does not seem too important as  the new consolidated update list is still created when only seeing this error.

    Cannot convert value "\\HSCUSCHLWS00079\root\sms\site_HCC:SMS_AuthorizationList
    .CI_ID=55004" to type "System.Management.ManagementObject". Error: "Not found "
    At C:\powershellscript\consolidated_updatelist.ps1:38 char:24
    +     $UpdateList = [wmi] <<<< "$($UpdateList.__PATH)"
        + CategoryInfo          : NotSpecified: (:) [], RuntimeException
        + FullyQualifiedErrorId : RuntimeException

    (Line 38 is the following: $UpdateList = [wmi]"$($UpdateList.__PATH)")

    This is the key error as the new consolidated update list is not created:

    (Line 99 is the following command:  $WmiAuthClassInst.Put())

    Exception calling "Put" with "0" argument(s): "Generic failure "
    At C:\powershellscript\consolidated_updatelist.ps1:99 char:22
    + $WmiAuthClassInst.Put <<<< ()
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    SCCM Power Shell Script:

    #Historical Updates
    $Hist="Prior to February 2012"

    #Month 1
    $Month1="2012 02 Feb All"

    #Month 2
    $Month2="2012 03 Mar All"

    #Month 3
    $Month3="2012 04 Apr All"

    #Month 4
    $Month4="2012 05 May All"


    #SCCM Site Server Details
    $SiteServer = "XXXXXXX"

    #SCCM NameSpace
    $SmsNamespace = "root\sms\site_XXX"

    #Softare Update List Name
    $UpdateListName = "May2012Consolidated"


    # Retrieve an array of all Update List objects
    $UpdateLists = Get-WmiObject -Namespace $SmsNameSpace -Class SMS_AuthorizationList
    $UpdateListComp = @()


    # Iterate over each Update List object in results
    foreach ($UpdateList in $UpdateLists)
    {
        # Using the __PATH property, obtain a direct reference to the instance
        $UpdateList = [wmi]"$($UpdateList.__PATH)"

    #Note: added to try to increase timing to assist with issue, but did not work.

        $UpdateList.PSBase.Options.Timeout = '0:1:00'

        # Iterate over each update CI_ID in the Updates array
        foreach ($Update in $UpdateList.Updates)
        {
        IF (($UpdateList.LocalizedDisplayName -eq "$Hist") -or ($UpdateList.LocalizedDisplayName -eq "$Month1") -or ($UpdateList.LocalizedDisplayName -eq "$Month2") -or ($UpdateList.LocalizedDisplayName -eq "$Month3") -or ($UpdateList.LocalizedDisplayName -eq "$Month4"))
            {

            #write-host "$Update.CI_ID"

            #Write-Host "Press any key to continue ..."
            #$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")        



            #Get a reference to the update we're working with, based on its CI_ID
                $Update = Get-WmiObject -Namespace $SmsNameSpace -Query "select * from SMS_SoftwareUpdate where CI_ID = '$Update'"
                $UpdatelistComp += @($Update.CI_ID)

            #Write-Host "Press any key to continue ..."
            #$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

            }
        }
    }

    #Create and populate an Instance of the SMS_CI_LocalizedProperties object
    $WmiLocalClassInst = ([WmiClass]('\\' + $SiteServer + '\' + $SmsNamespace + ':SMS_CI_LocalizedProperties')).CreateInstance()
    $WmiLocalClassInst.DisplayName = $UpdateListName
    $WmiLocalClassInst.LocaleID = $LocaleID

    #Create array type
    [System.Management.ManagementObject[]] $NewDescriptionInfo += $WmiLocalClassInst

    #Create a new UpdateList Object
    $WmiAuthClassInst = ([WmiClass]('\\' + $SiteServer + '\' + $SmsNamespace + ':SMS_AuthorizationList')).CreateInstance()




    #Populate the UpdateList properties.
    #Updates is an int32 array that maps to the CI_ID in SMS_SoftwareUpdate
    $WmiAuthClassInst.Updates = $UpdateListComp
    #Write-Host $UpdateList


    #Need to pass embedded properties (LocalizedInformation) here
    $WmiAuthClassInst.LocalizedInformation = $NewDescriptionInfo
    #Save the new UpdateList and properties
    $WmiAuthClassInst.Put()

                    

    Karl


    Karl

    04 Juni 2012 19:45

Semua Balasan

  • Surely someone must know how to assist.  The script only fails when there is a very large update list.

    It has to be some sort of timeout.

    Karl

    05 Juni 2012 15:14