web analytics

Blog

[SDK]How to Create a Configuration Manager Console Folder

Posted by:

Updated 24.03.2015

To to Create a Configuration Manager Console Folder

  1. Set up a connection to the SMS Provider.
  2. Create an instance of the SMS_ObjectContainerNode class.
  3. Populate the Name, ObjectType, and ParentContainerNodeID properties.
  4. Commit the changes.

Examples

Possible ObjectType values:

Example Output

New-CM12SDKFolder_Output

You can download the code examples from here 



About the Author:

Kaido Järvemets is a developer, consultant, trainer specializing in Microsoft System Center Configuration Manager and PowerShell Solutions at Coretech. Kaido frequently speaks at European conferences and had his US debut as speaker at MMS April 2013. Kaido is well-known in the Configuration Manager communities where he’s a key player in the PowerShell game. Kaido host one of the most complete Configuration Manager PowerShell library’s in the world with hundreds of free code samples ready to download and implement – www.cm12sdk.net. Kaido has been awarded Microsoft Most Valuable Professional (MVP) in Microsoft Enterprise Client Management for his work with Configuration Manager from 2011 – to present. Kaido is the founder of System Center User Group Estonia in 2011.

Discussion

  1. Young Pae  January 24, 2013

    1. With SCCM 2012 SP1 / PowerShell 3.0 verb naming convention in mind, I would rename Example #5’s function name to Add-CMFolder
    2. In order to create sub-folder of the folder you just created within the same script, you have to have a new function like Get-CMFolder and run it first before you create subfolder. Otherwise, parent folder’s ContainerNodeID is null and the subsequent Folder creation will fail.

    (reply)
    • admin  January 24, 2013

      1. Yes the function name can be Add-CMFolder also.
      2. This script example shows only how to create a folder and it will not check any other things. CM12SDK.net site contains simple examples how the CM Administrator/Developer can do sertain things and you need to add these different requirements on your own. ParentContainerNodeID is a required parameter and the root folder ID is always 0.
      For the Kent Agerlund “System Center 2012 Configuration Manager Mastering the Fundaments” book I added Get-CMFolder functionality.

      (reply)
      • Young Pae  January 24, 2013

        Thanks for the update.
        BTW, I have that book and I love its content in general! :) However, as SCCM 2012 SP1 comes with whole new way of doing things with PowerShell so I didn’t bother to check out “custom” methods. Maybe I should focus on what SP1 PowerShell brings in and still reference whatever SP1 doesn’t provide… Young-

        (reply)
        • Young Pae  January 24, 2013

          1. After a few hours later, I just realized that SCCM 2012 SP1’s PSD1 already came with *New-CMFolder* cmdlet (Not Create- nor Add-)!!!
          2. Get-CMFolder is still missing on PSD1 so yours or mine would be useful.
          3. Your Get-CMFolder use more user-friendly parameters + wide-open -filter “statement” while mine had more matching WMIObject parameters with specific items like ObjectType and ParentContainerNodeId. Either way, works fine for me.

          Even though I wasted a few hours last night to make your and my Add-CMFolder and Get-CMFolder working, it was quite useful and educational… :)

          Thanks again,

          Young-

          (reply)
          • admin  January 25, 2013

            Very Interesting but I dont see on MY CM12 SP1 RTM box NEW-CMFOLDER CMDLET.

  2. Young Pae  January 24, 2013

    For example:

    #Syntax: Get-CMFolder -SiteCode PS1 -SiteServer CM2-PS1 -Name “New APP Folder” -ObjectType 6000 -ParentContainerNodeId 0
    Function Get-CMFolder
    {
    [CmdLetBinding()]
    Param(
    [Parameter(Mandatory=$True,HelpMessage=”Please Enter Site Server Site code”)]
    $SiteCode,
    [Parameter(Mandatory=$True,HelpMessage=”Please Enter Site Server Name”)]
    $SiteServer,
    [Parameter(Mandatory=$True,HelpMessage=”Please Enter Folder Name”)]
    $Name,
    [Parameter(Mandatory=$True,HelpMessage=”Please Enter Folder Object Type”)]
    $ObjectType,
    [Parameter(Mandatory=$True,HelpMessage=”Please Enter parent folder ID”)]
    $ParentContainerNodeId
    )

    #$Arguments = @{Name = $Name; ObjectType = “$ObjectType”; ParentContainerNodeId = “$ParentContainerNodeId”}
    Try{
    Get-WmiObject -Namespace “root\sms\Site_$SiteCode” -Class “SMS_ObjectContainerNode”
    -Filter "Name='$Name' AND ObjectType=$ObjectType AND ParentContainerNodeId = $ParentContainerNodeId"

    -ComputerName $SiteServer -ErrorAction STOP
    }
    Catch{
    $_.Exception.Message
    }
    }

    $Result1 = Add-CMFolder -SiteCode PS1 -SiteServer Server1 -Name “New App Folder1″ -ObjectType 6000 -ParentContainerNodeId 0 #Create New App Folder1

    $Result2 = Get-CMFolder -SiteCode PS1 -SiteServer Server1 -Name “New App Folder1″ -ObjectType 6000 -ParentContainerNodeId 0 #Get New App Folder1 Object

    $Result2.ContainerNodeID #Return ContainerNodeID (To be used on the next line as ParentContainerNodeId)

    $Result3 = Add-CMFolder -SiteCode PS1 -SiteServer Server1 -Name “New App Folder2″ -ObjectType 6000 -ParentContainerNodeId $Result2.ContainerNodeID #Create New App Folder2 under New App Folder1

    I hope this helps… :)

    (reply)
  3. Young Pae  February 6, 2013

    Hi I was wrong.
    1. You were right that New-CMFolder is right verb (Add- is used only if you are adding something to “existing” object.
    2. There is no New-CMFolder on SCCM2012SP1. (When I have a fresh PowerSehll session with nothing but SCCM2012SP1, New-CMFolder wasn’t listed)
    3. Other than Get-CMFolder cmdlet I posted here, you can actually delete the comments…

    Thanks!

    (reply)
  4. Roshan  March 27, 2013

    Instead of using direct WMI e.g. Set-WmiInstance, [WmiClass] etc…
    Has anyone tried using (Get-PSdrive -PsProvider CMsite).Connection.CreateInstance(“SMS_ObjectContainerNode”) ?
    Isn’t it better to use CreateInstance a SDK method ? so that a status message is recorded.

    (reply)
    • admin  April 2, 2013

      Hi,

      Good Point :) and I haven´t tried your method. I will look into that.

      Best,
      Kaido

      (reply)

Add a Comment