Windows 컴퓨터 속성 검색 데이터 원본

Microsoft.SystemCenter.WindowsComputerPropertyDiscovery (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsSystem.PrivilegedMonitoringAccount
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DataSource DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$간격(초)
TimeoutSecondsint$Config/TimeoutSeconds$시간 제한(초)

Source Code:

<DataSourceModuleType ID="Microsoft.SystemCenter.WindowsComputerPropertyDiscovery" Accessibility="Internal" RunAs="System!System.PrivilegedMonitoringAccount" Batching="false">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>System!System.Discovery.MapperSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DataSource" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>DiscoverWindowsComputerProperties.js</ScriptName>
<Arguments>0 $MPElement$ $Target/Id$ $Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Arguments>
<ScriptBody><Script>
//-------------------------------------------------------------------------------
// DiscoverWindowsComputerProperties.js
//
// Script discovers the extended properties from AD/WMI given the
// DNS name of the computer.
//-------------------------------------------------------------------------------

var oAPI = new ActiveXObject("MOM.ScriptAPI");
var oShell = new ActiveXObject("WScript.Shell");
var oArgs = WScript.Arguments;

var SCRIPT_NAME = "DiscoverWindowsComputerProperties.js";
var ENU_MESSAGE_BASE = "Windows Property Discovery. ";

// Process Arguments:
// 0 - SourceType
// 1 - SourceId
// 2 - ManagedEntityId
// 3 - ComputerIdentity
// 4 - ManagementGroupName

var SourceType, SourceId, ManagedEntityId, ComputerIdentity, ManagementGroupName;

SourceType = oArgs(0);
SourceId = oArgs(1);
ManagedEntityId = oArgs(2);
ComputerIdentity = oArgs(3);

var oDiscovery = oAPI.CreateDiscoveryData(SourceType, SourceId, ManagedEntityId);

// Need to retrieve these properties
var strDNSComputerName = ComputerIdentity,
strNetBIOSDomain = null,
strNetBIOSComputerName = null,
strNetBIOSHostName = null,
strDomainDnsName = null,
strForestDnsName = null,
strSite = null,
strComputerOU = null,
strIPAddresses = null,
strLogicalProcessors = null,
strPhysicalProcessors = null,
strHostServerName = null,
strVirtualMachineName = null;

var strDomainDN = null;

// Attempt to do things the 'right' way
try
{
var objWMIService = ConnectToWMI(strDNSComputerName);
var objComputer = GetWMIComputerSystem(objWMIService, strDNSComputerName);

try
{
// Get the domain data. If computer is in a workgroup, it will catch exception.
strDomainDN = DNDomainFromDNS(strDomainDnsName);
}
catch (e)
{
WScript.Echo("Domain Data Exception caught for " + strDomainDnsName);
}

if (strDomainDN != null)
{
strNetBIOSDomain = NetBIOSDomainFromDN(strDomainDN);
}

strIPAddresses = GetIPAddresses(objWMIService);

WScript.Echo("Creating ADSystemInfo object on " + strNetBIOSHostName);

// Attempt to remotely create the System Info object
var adSys = new ActiveXObject("ADSystemInfo", strNetBIOSHostName);

strComputerOU = GetComputerOUFromDN(adSys.ComputerName);
strForestDnsName = adSys.ForestDNSName;
strSite = adSys.SiteName;
}

// Unable to contact the machine, (mis)use the DNS name
catch (e)
{
WScript.Echo("Exception retrieving properties '" + e.number + ": " + e.description + "', using failsafe method"); // Do nothing
}

if (IsNullOrEmpty(strNetBIOSComputerName) || IsNullOrEmpty(strNetBIOSDomain))
{
// Try to parse the DNS name of the system
var arrNameSplit = strDNSComputerName.split(".");
if (IsNullOrEmpty(strNetBIOSComputerName) &amp;&amp; arrNameSplit.length &gt; 0)
{
strNetBIOSComputerName = arrNameSplit[0];
}
if (IsNullOrEmpty(strNetBIOSDomain) &amp;&amp; arrNameSplit.length &gt; 1)
{
strNetBIOSDomain = arrNameSplit[1];
}

// If there is no DNS name (no '.') then this is a workgroup, so use the domain name from WMI as NetBIOS Domain
if (IsNullOrEmpty(strNetBIOSDomain) &amp;&amp; !IsNullOrEmpty(strDomainDnsName))
{
strNetBIOSDomain = strDomainDnsName;
}
}

if (IsNullOrEmpty(strDomainDnsName))
{
for (var i = 1; i &lt; arrNameSplit.length; i++)
{
if (!IsNullOrEmpty(strDomainDnsName))
{
strDomainDnsName = strDomainDnsName + ".";
strDomainDnsName = strDomainDnsName + arrNameSplit[i];
}
else
{
strDomainDnsName = arrNameSplit[i];
}
}
}

// Get the ComputerOU if we have the NetBIOS and Domain DN
if (IsNullOrEmpty(strComputerOU) &amp;&amp;
!IsNullOrEmpty(strNetBIOSComputerName) &amp;&amp;
!IsNullOrEmpty(strDomainDN))
{
try
{
strComputerOU = GetComputerOUFromDN("cn="+strNetBIOSComputerName+","+strDomainDN);
}
catch (e)
{
; // Nothing to be done
}
}

// Get the forest if we have the Domain DNS name
if (IsNullOrEmpty(strForestDnsName) &amp;&amp;
!IsNullOrEmpty(strDomainDnsName))
{
strForestDnsName = ForestFromDomainDNS(strDomainDnsName);
}

// Get the site name
if (IsNullOrEmpty(strSite))
{
strSite = GetSiteFromComputerDNS(strDNSComputerName);
}

// Get the virtual machine information
GetVirtualInfoFromReg(strDNSComputerName);

WScript.Echo("NetBIOS Computer Name: " + strNetBIOSComputerName);
WScript.Echo("NetBIOS Domain Name: " + strNetBIOSDomain);
WScript.Echo("Forest DNS Name: " + strForestDnsName);
WScript.Echo("Domain DNS Name: " + strDomainDnsName);
WScript.Echo("AD Site: " + strSite);
WScript.Echo("OU: " + strComputerOU);
WScript.Echo("IP Addresses: " + strIPAddresses);
WScript.Echo("Logical Processors: " + strLogicalProcessors);
WScript.Echo("Physical Processors: " + strPhysicalProcessors);
WScript.Echo("Host Server Name: " + strHostServerName);
WScript.Echo("Virtual Machine Name: " + strVirtualMachineName);

var oInstance = oDiscovery.CreateClassInstance("$MPElement[Name='Windows!Microsoft.Windows.Computer']$");
AddClassProperty(oInstance, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", ComputerIdentity);
AddClassProperty(oInstance, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/NetbiosComputerName$", strNetBIOSComputerName);
AddClassProperty(oInstance, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/NetbiosDomainName$", strNetBIOSDomain);
AddClassProperty(oInstance, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/ForestDnsName$", strForestDnsName);
AddClassProperty(oInstance, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/DomainDnsName$", strDomainDnsName);
AddClassProperty(oInstance, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/ActiveDirectorySite$", strSite);
AddClassProperty(oInstance, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/OrganizationalUnit$", strComputerOU);
AddClassProperty(oInstance, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/IPAddress$", strIPAddresses);
AddClassProperty(oInstance, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/LogicalProcessors$", strLogicalProcessors);
AddClassProperty(oInstance, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PhysicalProcessors$", strPhysicalProcessors);
AddClassProperty(oInstance, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/HostServerName$", strHostServerName);
AddClassProperty(oInstance, "$MPElement[Name='Windows!Microsoft.Windows.Computer']/VirtualMachineName$", strVirtualMachineName);

oDiscovery.AddInstance(oInstance);
oAPI.Return(oDiscovery);


//--------------------------------------------------------------
// Tests for NULL or Empty
//--------------------------------------------------------------
function IsNullOrEmpty(str)
{
return null == str || 0 == str.length;
}

//--------------------------------------------------------------
// Connects to WMI on the specified computer
//--------------------------------------------------------------
function ConnectToWMI(strDNSComputerName)
{
return GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" + strDNSComputerName + "\\root\\cimv2");
}


//--------------------------------------------------------------
// Gets the WMI Computer object for the given DNS computer name
//--------------------------------------------------------------
function GetWMIComputerSystem(objWMIService, strDNSComputerName)
{
var E_CLUSTER_RESOURCE_NOT_FOUND = -2146823281;

// Get the computer from the system
var astrSplit, colSettings, objComputer;
astrSplit = strDNSComputerName.split(".");
strNetBIOSComputerName = astrSplit[0];

try
{
colSettings = new Enumerator(objWMIService.ExecQuery(
"Select Domain, Name, NumberOfLogicalProcessors, NumberOfProcessors from Win32_ComputerSystem WHERE Name=\"" + strNetBIOSComputerName + "\""));
objComputer = colSettings.item();
strDomainDnsName = objComputer.Domain;
strNetBIOSHostName = objComputer.Name;
strLogicalProcessors = objComputer.NumberOfLogicalProcessors;
strPhysicalProcessors = objComputer.NumberOfProcessors;
if (null == strLogicalProcessors)
{
strLogicalProcessors = objComputer.NumberOfProcessors;
strPhysicalProcessors = null;
}
}
catch (e)
{
if (e.number != E_CLUSTER_RESOURCE_NOT_FOUND)
{
throw e;
}

colSettings = new Enumerator(objWMIService.ExecQuery("Select Domain, Name, NumberOfLogicalProcessors, NumberOfProcessors from Win32_ComputerSystem"));
objComputer = colSettings.item();
strDomainDnsName = objComputer.Domain;
strNetBIOSHostName = objComputer.Name;
strLogicalProcessors = objComputer.NumberOfLogicalProcessors;
strPhysicalProcessors = objComputer.NumberOfProcessors;
if (null == strLogicalProcessors)
{
strLogicalProcessors = objComputer.NumberOfProcessors;
strPhysicalProcessors = null;
}
}
return objComputer;
}


//-----------------------------------------------------------
// Returns the DN domain name from DNS
//-----------------------------------------------------------
function DNDomainFromDNS(strDNSDomain)
{
// Determine DN domain name from RootDSE object.
var objRootDSE = GetObject("LDAP://" + strDNSDomain + "/RootDSE");
return objRootDSE.Get("defaultNamingContext");
}


//-----------------------------------------------------------
// Returns the forest for the domain
//-----------------------------------------------------------
function ForestFromDomainDNS(strDNSDomain)
{
var strForestDNS = null;
try
{
var objRootDSE = GetObject("LDAP://" + strDNSDomain + "/RootDSE");
var strForestDN = objRootDSE.Get("rootdomainNamingContext");

// We got the DN (DC=corp,DC=microsoft,DC=com), translate to DNS (corp.microsoft.com)
var arrParseDN = strForestDN.split(",");
for (var i = 0; i &lt; arrParseDN.length; i++)
{
var arrParseDC = arrParseDN[i].split("=");
if (null == strForestDNS)
{
strForestDNS = arrParseDC[1];
}
else
{
strForestDNS = strForestDNS + "." + arrParseDC[1];
}
}
}
catch (e)
{
; // Nothing to be done
}
return strForestDNS;
}

//-----------------------------------------------------------
// Returns the NetBIOS domain name from the DNS domain name
//-----------------------------------------------------------
function NetBIOSDomainFromDN(strDNDomain)
{
// Constants for the NameTranslate object.
var ADS_NAME_INITTYPE_GC = 3;
var ADS_NAME_TYPE_NT4 = 3;
var ADS_NAME_TYPE_1779 = 1;

var objTrans, strNetBIOSDomain;

// Use the NameTranslate object to find the NetBIOS domain name from the
// DNS domain name.
objTrans = new ActiveXObject("NameTranslate");
objTrans.Init(ADS_NAME_INITTYPE_GC, "");
objTrans.Set(ADS_NAME_TYPE_1779, strDNDomain);
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4);

// Remove trailing backslash.
return strNetBIOSDomain.slice(0,strNetBIOSDomain.length - 1);
}


//-------------------------------------------------------------
// Gets the IP addresses for the given computer name
//-------------------------------------------------------------
function GetIPAddresses(objWMIService)
{
var wbemFlagForwardOnly = 32;
var wbemFlagReturnImmediately = 16;
var strIPs;
var oItem, propValue;
var arrItems;

arrItems = new Enumerator(objWMIService.ExecQuery(
"Select IPAddress from Win32_NetworkAdapterConfiguration",
"WQL",
wbemFlagForwardOnly+wbemFlagReturnImmediately));
for (;!arrItems.atEnd(); arrItems.moveNext())
{
var IPValue = arrItems.item().IPAddress;
if (null != IPValue)
{
var arrIPs = IPValue.toArray();

for (var i =0; i &lt; arrIPs.length; i++)
{
var strIP = arrIPs[i];
if (null != strIP)
{
if (null == strIPs)
{
strIPs = strIP;
}
else
{
var matchIP = strIPs.search(strIP);
if(matchIP == -1)
{
strIPs = strIPs + ", " + strIP;
}
}
}
}
}
}

return strIPs;
}


//-----------------------------------------------------------
// Returns the Computer OU from the given Computer DN
//-----------------------------------------------------------
function GetComputerOUFromDN(strComputerDN)
{
var ADS_SETTYPE_DN = 4;
var ADS_FORMAT_X500_PARENT = 8;

var oPathName = new ActiveXObject("PathName");
oPathName.Set(strComputerDN, ADS_SETTYPE_DN);
return oPathName.Retrieve(ADS_FORMAT_X500_PARENT);
}


//-----------------------------------------------------------
// Get the site name from the Computer DNS
//-----------------------------------------------------------
function GetSiteFromComputerDNS(strComputerDNS)
{
var HKEY_LOCAL_MACHINE = 0x80000002;
var strSiteName = null;

try
{
var objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" + strComputerDNS + "\\root\\default:StdRegProv");

// Get the WMI method and setup the params
var objMethod = objReg.Methods_.Item("GetStringValue");
var objInParam = objMethod.InParameters.SpawnInstance_();
objInParam.hDefKey = HKEY_LOCAL_MACHINE;
objInParam.sSubKeyName = "System\\CurrentControlSet\\Services\\Netlogon\\Parameters";
objInParam.sValueName = "SiteName";

// Execute the method and retrieve the value
var objOutParam = objReg.ExecMethod_(objMethod.Name, objInParam);
strSiteName = objOutParam.sValue;

//If SiteName override is null or empty, try DynamicSiteName
if(strSiteName == null || strSiteName == "")
{
objInParam.sValueName = "DynamicSiteName";
// Execute the method and retrieve the value
objOutParam = objReg.ExecMethod_(objMethod.Name, objInParam);
strSiteName = objOutParam.sValue;
}
}
catch(e)
{
; // Nothing to be done
}

return strSiteName;

}

//-----------------------------------------------------------
// Get the virtual machine information from the registry
//-----------------------------------------------------------
function GetVirtualInfoFromReg(strComputerDNS)
{
var HKEY_LOCAL_MACHINE = 0x80000002;

try
{
var objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" + strComputerDNS + "\\root\\default:StdRegProv");

// Get the WMI method and setup the params
var objMethod = objReg.Methods_.Item("GetStringValue");
var objInParam = objMethod.InParameters.SpawnInstance_();
objInParam.hDefKey = HKEY_LOCAL_MACHINE;
objInParam.sSubKeyName = "SOFTWARE\\Microsoft\\Virtual Machine\\Guest\\Parameters";

objInParam.sValueName = "HostName";
// Execute the method and retrieve the value
var objOutParam = objReg.ExecMethod_(objMethod.Name, objInParam);
strHostServerName = objOutParam.sValue;

objInParam.sValueName = "VirtualMachineName";
// Execute the method and retrieve the value
var objOutParam = objReg.ExecMethod_(objMethod.Name, objInParam);
strVirtualMachineName = objOutParam.sValue;
}
catch(e)
{
; // Nothing to be done
}
}

//-----------------------------------------------------------
// Adds the property to the instance if the value is non-null
//-----------------------------------------------------------
function AddClassProperty(oInstance, strProperty, strValue)
{
if (null != strValue) oInstance.AddProperty(strProperty, strValue);
}

</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DataSource"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>