Your company's ad could live here and reach over 50,000 people a month!

Share This Post

Perform Actions with SMS Web Reporting, Volume 2: Create a Computer Association

Overview:

Make sure you have already reviewed Volume 1, and have completed at least the “Getting started:” section. This installment uses the SMS_StateMigration class to associate an old computer to its shiny new replacement.

Creating a new action:

Create a new text file named AssocComp.asp with the following code:

<head>      

<title>Computer Association</title>       

</head>

<html>      

<body onload=”window.opener.close();”>       

<h1>Associating computers, please wait.</h1>       

<h2>View the &quot;List of computer associations&quot; report to verify that the association was created.</h2>

<%      

    ‘ GET VARIABLES PASSED IN URL       

    strSite = Request.QueryString(“Site”)       

    strServer = Request.QueryString(“Server”)       

    strRefID = Request.QueryString(“Ref”)       

    strDesID = Request.QueryString(“Des”)       

    strRefName = Request.QueryString(“RefName”)

    ‘ GET THE STATE MIGRATION CLASS       

    Set SWbemLocator=CreateObject(“WbemScripting.SWbemLocator”)       

    set SWbemServices = SWbemLocator.ConnectServer(strServer,”root\SMS\site_”& strSite)       

    Set stateMigrationClass = SWbemServices.Get(“SMS_StateMigration”)

    ‘ SET UP PARAMETERS      

    Set inParams = _       

        stateMigrationClass.Methods_(“AddAssociation”).InParameters.SpawnInstance_   

        inParams.SourceClientResourceID = strRefID       

    inParams.RestoreClientResourceID = strDesID

    ‘ CALL THE METHOD       

    Set outParams = _       

        SWbemServices.ExecMethod( “SMS_StateMigration”, “AddAssociation”, inParams)        

%>       

<script language=javascript>       

    window.open(”,’_self’,”);       

    setTimeout(“window.close()”,3000);       

</script>       

</body>       

</html>

Creating a report to drive the action:

Within the Configuration Manager Console, start the New Report Wizard. Your SQL statement will look like this:

SELECT TOP 1      

    [G1].[Name0] AS [From:],       

    [G2].[Name0] AS [To:],       

    [G1].[ResourceID] AS [Ref],       

    [G2].[ResourceID] AS [Des]       

FROM [v_GS_System] [G1]       

INNER JOIN [v_GS_System] [G2]       

ON 1=1       

WHERE [G1].[Name0] = @RefComp       

AND [G2].[Name0] = @DesComp       

ORDER BY        

    [G1].[TimeStamp] DESC,       

    [G2].[TimeStamp] DESC

Add the following prompts:

RefComp: SELECT Name0 FROM v_GS_SYSTEM WHERE Name0 LIKE @__filterwildcard ORDER BY Name0

CollectionID: (Exactly the same as RefComp)

Add this link, where YYY is the site code and ZZZZ is the server name: supplemental/actions/assoccomp.asp?Site=YYY&Server=ZZZZ&Ref=<3>&Des=<4>&RefName=<1>

Using the report:

Run the report like any other. Select the reference and destination computers and click the Display button. Validate that the computers on the next page are indeed the two you wanted to associate, and click the image_thumb3 button to the left. The AssocComp.asp file takes the input from the link you created, and creates a computer association.

Share This Post

Leave a Reply