Configuration Manager 의 instance SMS_Query만들어 기반 쿼리를 만듭니SMS_Query다. 클래스 Expression 개체는 SMS_Query WQL 쿼리를 정의합니다. 쿼리 결과를 특정 컬렉션으로 제한하려면 속성에서 LimitToCollectionID 컬렉션 식별자를 지정합니다.
참고
쿼리를 만들면 쿼리 아래의 Configuration Manager 콘솔에 표시됩니다.
쿼리를 만들려면
SMS 공급자에 대한 연결을 설정합니다. 자세한 내용은 SMS 공급자 기본 사항을 참조하세요.
SMS_Query instance 만듭니다.
SMS_Query속성을 채웁 수 있습니다.를 커밋합니다
SMS_Query.필요한 경우 쿼리 개체를 검색하고 쿼리 식별자를 가져옵니다.
예제
다음 예제 메서드는 모든 시스템에 대해 쿼리하는 클래스 쿼리를 만듭니다 SMS_Query . 메서드는 쿼리 식별자를 반환하며, 이 식별자는 Configuration Manager 쿼리를 실행하는 방법의 예제에 대한 입력으로 사용할 수 있습니다.
샘플 코드 호출에 대한 자세한 내용은 코드 조각 Configuration Manager 호출을 참조하세요.
Function CreateQuery(connection)
On Error Resume Next
Dim query
Dim path
' Create a query object.
Set query = connection.Get("SMS_Query").SpawnInstance_()
If Err.Number<>0 Then
Wscript.Echo "Couldn't create query object"
CreateQuery = Null
Exit Function
End If
' Populate the object.
query.Comments = "A query for all systems"
query.Expression = "select Name, " + _
"SMSAssignedSites, " + _
"IPAddresses, " + _
"IPSubnets, " + _
"OperatingSystemNameandVersion, " + _
"ResourceDomainORWorkgroup, " + _
"LastLogonUserDomain, " + _
"LastLogonUserName, " + _
"SMSUniqueIdentifier, " + _
"ResourceId, " + _
"ResourceType, " + _
"NetbiosName " + _
"from sms_r_system"
query.LimitToCollectionID = nothing
query.Name = "Query All Systems"
query.TargetClassName = "SMS_R_System"
' Commit the object
path = query.Put_
If Err.Number<>0 Then
Wscript.Echo "Couldn't commit the query"
CreateQuery = Null
Exit Function
End If
WScript.Echo "Query created"
' Get the object back to get the query identifier.
Set query = connection.Get(path)
CreateQuery = query.QueryID
End Function
public string CreateQuery(WqlConnectionManager connection)
{
try
{
// Create an SMS_Query object.
IResultObject query = connection.CreateInstance("SMS_Query");
// Populate the object.
query["Comments"].StringValue = "A query for all systems";
query["Expression"].StringValue =
"select Name, " +
"SMSAssignedSites, " +
"IPAddresses, " +
"IPSubnets, " +
"OperatingSystemNameandVersion, " +
"ResourceDomainORWorkgroup, " +
"LastLogonUserDomain, " +
"LastLogonUserName, " +
"SMSUniqueIdentifier, " +
"ResourceId, " +
"ResourceType, " +
"NetbiosName " +
"from sms_r_system";
query["LimitToCollectionID"].StringValue = null;
query["Name"].StringValue = "Query All Systems";
query["TargetClassName"].StringValue = "SMS_R_System";
// Commit the query.
query.Put();
// Get the query - allows access to the queryID.
query.Get();
// Return the query identifier.
return query["QueryID"].StringValue;
}
catch (SmsException e)
{
Console.WriteLine("Failed to run the query: " + e.Message);
throw;
}
}
예제 메서드에는 다음 매개 변수가 있습니다.
| 매개 변수 | 형식 | 설명 |
|---|---|---|
connection |
-관리: WqlConnectionManager- VBScript: SWbemServices |
- SMS 공급자에 대한 유효한 연결입니다. |
코드 컴파일
C# 예제에는 다음과 같은 컴파일 요구 사항이 있습니다.
네임스페이스
시스템
System.Collections.Generic
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
어셈블리
microsoft.configurationmanagement.managementprovider
adminui.wqlqueryengine
강력한 프로그래밍
오류 처리에 대한 자세한 내용은 Configuration Manager 오류 정보를 참조하세요.
.NET Framework 보안
Configuration Manager 애플리케이션 보안에 대한 자세한 내용은 역할 기반 관리 Configuration Manager 참조하세요.
참고 항목
Configuration Manager 쿼리 정보Configuration Manager 쿼리를 실행하는 방법