web analytics

Blog

[SDK][ADVANCED]How to replicate AD DS OU structure to Configuration Manager

Posted by:

Updated 24.03.2015

To replicate AD DS OU structure to Configuration Manager

  1. Build a sample OU structure in your demo/lab environment
  2. Find out starting OU DistinguishedName
  3. Run the Replicate-ADDS-OU-Structure-TO-ConfigMgr.ps1 like this

Example

Sample Output

AD_Structure

CM_Structure

You can download this code example from here 

References



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. Bill Y  April 15, 2013

    I keep getting the below error when I run this powershell script, any ideas as to why?

    Set-WmiInstance : Generic failure
    At C:\temp\Replicate_ADDS_Structure.ps1:31 char:17
    + Set-WmiInstance -Namespace “root\sms\site_$($SiteCode)” -Class ” …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [Set-WmiInstance], ManagementException
    + FullyQualifiedErrorId : SetWMIManagementException,Microsoft.PowerShell.Commands.SetWmiInstance

    (reply)
    • admin  April 16, 2013

      Hi,

      Please open up the SMSPROV.log file and then you will see the reason why it failed.

      Best,
      Kaido

      (reply)
      • Bill Y  April 18, 2013

        It seems to fail due to:
        *~*~e:\nts_sccm_release\sms\siteserver\sdk_provider\smsprov\sspfolder.cpp(481) : A folder with this name already exists.~*~* SMS Provider 4/18/2013 9:45:18 AM 1544 (0x0608)

        The issue is that we have subfolders named the same. i.e.-:
        Folder1
        workstations
        Folder2
        workstations

        Any suggestions?

        (reply)
        • admin  April 19, 2013

          Hi,

          Nope, it cant be that issue because you can create subfolders with same name. You can try it via CM console. I will retest it on my test lab.

          Best,
          Kaido

          (reply)
        • admin  April 19, 2013

          Hi again,

          I just tested it again and it worked. I did one simple OU structure like this:
          -Contoso
          –New York
          —Workstations
          -Dallas
          —Workstations

          Best,
          Kaido

          (reply)
          • Bill Y  April 26, 2013

            Here is my log. https://www.dropbox.com/s/udeh6sdbwnm42y4/SMSProv.log

            I narrowed it down to my smallest OU that gives me the error. I run this command from an Admin PowerShell prompt :
            (.\Replicate_ADDS_Structure.ps1 -SiteCode MCS -SiteServer Localhost -StartOU “OU=Workstations,OU=Beard,OU=Elementary School,DC=monet,DC=k12,DC=ca,DC=us”)

            I would love to use this, it will take a lot of tedium out of my setup but I just can’t seem to get this to work. Thanks for looking at it.

          • admin  May 1, 2013

            Hi,

            Can you show me your AD Structure? if yes, then I can build the same structure on my lab also.

            Best,
            Kaido

  2. Bill Y  May 1, 2013

    Here is our structure and I am running it against one of our workstation OU’s (Beard). There are anywhere from 30-100 room OU’s under workstation with the rare sub OU (Like Rm1-Lab1, Rm1-Lab2)

    Domain
    -High Schools
    –High School1
    —Workstations
    —-Rm1
    —-Rm2
    –High School2
    —Workstations
    —-Rm1
    —-Rm2
    -Elementaries
    –Beard
    —Workstations
    —-Rm1
    —-Rm2
    –Burbank
    —Workstations
    —-Rm1
    —-Rm2

    (reply)
  3. Jasper  July 9, 2013

    Just a tip:
    We are using 001 as site code and I needed to put the site code between quotes.

    Like: .\Replicate_AD_Structure.ps1 -SiteCode “001” ……………

    (reply)
  4. Jay  June 25, 2014

    How can I modify this to replicate the AD structure for user collections?

    (reply)
  5. Mahmoud  January 27, 2015

    it does not work with sccm 2012 R2 ??
    any update

    (reply)
  6. Eden  August 19, 2016

    Hi. First of all, thank you for your script.

    I would like to know how could I change this script to create the AD structure on my SCCM User Collection portion (not the device collection one).

    I have changed the ObjectType = 5000 to ObjectType = 5001, but I am getting a weird error complaining about the line 51 ( Set-WmiInstance -Namespace “root\SMS\Site_$($SiteCode)” -Class ‘SMS_ObjectContainerNode’ -Arguments $Arguments -ComputerName $SiteServer)

    Any suggestion?

    Thanks in Advance.

    Eden

    (reply)

Add a Comment