Skip to main content

PowerShell + SCCM 2012 R2 : Discovery

So my lab is all setup. Now before starting to manage Objects (Computers, Users etc. ) we need to discover them.

If you want to read more on Discovery in ConfigMgr, you can browse to this link.

For this post am trying to automate things done in this post at Windows-Noob.

Note - To manage ConfiMgr using PowerShell one needs the ConfigrationManger Module (this is available after you install Admin Console on a Client/ Server) loaded in the session, which can be done in two ways:

  1. You can open a PowerShell session and import the ConfigurationManager module.
  2. Import-Module -Name "$(split-path $Env:SMS_ADMIN_UI_PATH)\ConfigurationManager.psd1"
  3. Using ConfigMgr Admin Console you get an option to connect using PowerShell which essentially does the same thing done in above step.




Note: To run all the CM Cmdlets your location needs to be set to the CMSite and properties you reference are case sensitive. Below is the Screenshot showing that :


Now see the Property Reference thing I was referring to:



[I tried Implicit Remoting but the the PSDrive for the CMSite won't load on the PSSession while importing the Module.]

Step1 : Enable Discovery Methods

The Cmdlet used to work with configuring Discovery methods is:
Set-CMDiscoveryMethod
If you go and have a look at the Online help page for the cmdlet you will see that the parameter set names and the parameters are really very descriptive.

AD Forest Discovery [LogFile - ADForestDisc.log] : With ConfigMgr 2012 this is a new discover methods added which discovers AD Sites, Subnets and domains and gives an option to automatically create Boundaries based on it.

To enable it using PowerShell and run it ASAP the code is below:

So after this hit refresh on the ConfigMgr console and the changes reflect.

AD Group Discovery [Logfile - Adsgdis.log] :
BTW run this discovery method after you have run the AD System and User discovery as it creates partial DDR for the Computers and Users part of the Groups. Read more here.

I did hit a little bump while trying to configure this discovery, at first was able to configure all options properly except the one to set Discovery Scopes. Later on was able to do that after digging deep into the ConfigMgr SDK , trying out things via GUI to analyze them and found out that it is way easy to do in PowerShell by just issuing few CIM calls :)


Below is the code :



The Screenshots after running the above cmdlet:


               


AD System Discovery [Logfile : Adsysdis.log ]

I found out that the Set-CMDiscovery Cmdlet does have a parameter named -ActiveDirectoryContainer  but it throws an error when you use that so I went ahead and did it using CIM Cmdlets ;)

Note that the schedule in which discovery is running in my Environment are very short durations...it's just my Lab environment you shouldn't do that in a Production as it could be overwhelming for the Site Servers to process the discovery data.

Code is below:



Below is one of the Screenshots...not putting every screen up now. You can verify it in your environment. Play with the Script code a bit and you would explore what various values do.


AD User Discovery [Logfile : Adusrdis.log ]
Based on pretty much what is done with the AD Sys Discovery the PowerShell code is similar. Code is below


Network [LogFile : NetDisc.log ] & HeartBeat Discovery [ LogFile : InventoryAgent.log  (Client Side)]

Code below:


Now, this past week was interesting as I was reading the ConfigMgr SDK to figure out most of the things like setting AD Container for User/ System discovery but in the end it was lot of experimenting that made it work.

Also after you make changes to the Discovery methods, they won't reflect until you restarted the Component Manager service on the SCCM Server. This took me little time to figure out. Once you do this the relevant log files will spawn up or have the relevant entries about the run.

I must say I had my share of fun figuring things out...am hoping for more learning in next few weeks when I dive deep into  the ConfigMgr SDK ;)

Popular posts from this blog

Test connectivity via a specific network interface

Recently while working on a Private cloud implementation, I came across a scenario where I needed to test connectivity of a node to the AD/DNS via multiple network adapters.  Many of us would know that having multiple network routes is usually done to take care of redundancy. So that if a network adapter goes down, one can use the other network interface to reach out to the node. In order to make it easy for everyone to follow along, below is an analogy for the above scenario: My laptop has multiple network adapters (say Wi-Fi and Ethernet) connected to the same network. Now how do I test connectivity to a Server on the network only over say Wi-Fi network adapter?

PowerShell + SCCM : Run CM cmdlets remotely

Today I saw a tweet about using implicit remoting to load the Configuration Manager on my machine by Justin Mathews . It caught my eye as I have never really tried it, but theoretically it can be done. Note - The second tweet says "Cannot find a provider with the name CMSite", resolution to which is in the Troubleshooting section at the end.

Azure DevOps Tips & Tricks - Find private REST APIs

Original source -  Azure DevOps Tip - Find private APIs Often working with Azure DevOps, I hit a wall trying to automate some tasks but there are no REST API's made public yet. It was one of those task of automating creation of Environments in multi-stage YAML based pipelines in AzDO. Quick research reveals that this has been requested in uservoice  (please upvote). Let's see one of the very simple ways to discover some of these APIs.