2011년 3월 8일 화요일

Getting computers' name from AD in c#

I've been doing a job that add new some functionaries on my program.
One of them enable ours to run the following through SCDPM 2010.

  • Run backup & restore (I've already posted about restore, click here)
  • Create and Modify schedule.
  • Getting a bakup list
  • Install DPM agent

Today, I'd like to explain how to get computer's name from AD(active directory). 
When we try to add new server for protection into DPM, we should install agent first. We usually do that work through DPM console. the below picture is the first step while adding new protection server. As we can see, we have to choose servers what we want to.


When Adding DPM functionality to the program, It is effective way to convert powershell cmdlet to programming language, In my case, I use C#. All System Center products support powershell for improving manageability. 


I intended to implement to deploy DPM Agent on the desired host and I had to get computer's list from active directory as the first step. However, DPM doesn't provide any powershell cmdlet about this.


So I wrote c# code of it manually.



line 22, type the server name which installed domain controller.
line 27, narrow the target.(here, I only want to get computers)
line 28, add "Name" property to get computer's name only.


Below is web sites I had referenced.

http://www.dreamincode.net/code/snippet1847.htm
http://www.powershellpro.com/computernames-activedirectory/149/

댓글 없음:

댓글 쓰기