Running the SCCM SDK Example Code Snippets

Running the SCCM SDK Example Code Snippets

Overview

This page shows how to easily run the c# example code snippets from the SCCM SDK sections on this site. A small Visual Studio c# project was created that can be downloaded and modified to run the required example snippets.

The example Program and Wrapper.cs class (downloads below) is a basic C# console application that can be used to connect to SCCM and run the various example code snippets found on this site. Each example is designed to be as stand-alone as possible. You may have to edit the examples to work in your environment. Related examples may be bundled together in a single file. For example, all of the IResultObject disposal examples are in the file IResultObjectDisposal.cs.

Clone the entire SCCM SDK snippets repo below and use Visual Studio to compile and edit the examples.

Examples and Downloads

The examples on this page can be downloaded from the GitHub repo:

Wrapper Class

The wrapper class Wrapper.cs contains a Run() method that contains commented out example methods near the comment “Call snippets”. Simply uncomment the method you are interested in testing and examine that method to determine if it needs to be customised for your environment.

public void Run()
{
    // Connect to SCCM
 
    //
    // Call snippets - uncomment required snippets.
    //
 
    //
    // Fundamentals
    //
    //IResultObjectExecuteQueryDisposalV1(wqlConnection);
    //IResultObjectExecuteQueryDisposalV2(wqlConnection);
    //IResultObjectDisposalOfReturnValue(wqlConnection);
    //LazyPropertyFromQuery(wqlConnection);
 
    // Disconnect from SCCM
}
public void Run()
{
    // Connect to SCCM

    //
    // Call snippets - uncomment required snippets.
    //

    //
    // Fundamentals
    //
    //IResultObjectExecuteQueryDisposalV1(wqlConnection);
    //IResultObjectExecuteQueryDisposalV2(wqlConnection);
    //IResultObjectDisposalOfReturnValue(wqlConnection);
    //LazyPropertyFromQuery(wqlConnection);

    // Disconnect from SCCM
}