WMI를 사용하여 Configuration Manager SMS 공급자에 연결하는 방법

로컬 또는 원격 Configuration Manager 사이트 서버에 대한 SMS 공급자에 연결하기 전에 먼저 사이트 서버에 대한 SMS 공급자를 찾아야 합니다. SMS 공급자는 사용 중인 Configuration Manager 사이트 서버에 로컬 또는 원격일 수 있습니다. WMI(Windows Management Instrumentation) 클래스 SMS_ProviderLocation 는 모든 Configuration Manager 사이트 서버에 있으며, 한 인스턴스에는 사용 중인 Configuration Manager 사이트 서버의 위치가 포함됩니다.

WMI SWbemLocator 개체를 사용하거나 Windows 스크립트 호스트 GetObject 메서드를 사용하여 Configuration Manager 사이트 서버에서 SMS 공급자에 연결할 수 있습니다. 두 방법 모두 로컬 또는 원격 연결에서 동일하게 작동하며 다음과 같은 제한 사항이 있습니다.

  • 원격 컴퓨터에 사용자 자격 증명을 전달해야 하는 경우 를 사용해야 SWbemLocator 합니다.

  • 를 사용하여 SWbemLocator 로컬 컴퓨터에 사용자 자격 증명을 명시적으로 전달할 수 없습니다.

    연결이 로컬인지 원격인지에 따라 연결을 만드는 데 사용할 수 있는 몇 가지 구문이 있습니다. SMS 공급자에 연결되면 Configuration Manager 개체에 액세스하는 데 사용하는 SWbemServices 개체가 있습니다.

참고

연결에 대한 컨텍스트 한정자를 추가해야 하는 경우 WMI를 사용하여 Configuration Manager 컨텍스트 한정자를 추가하는 방법을 참조하세요.

SMS 공급자에 연결하려면

  1. WbemScripting.SWbemLocator 개체를 가져옵니다.

  2. 인증 수준을 패킷 개인 정보로 설정합니다.

  3. SWbemLocator 개체 ConnectServer 메서드를 사용하여 SMS 공급자에 대한 연결을 설정합니다. 원격 컴퓨터인 경우에만 자격 증명을 입력합니다.

  4. SMS_ProviderLocation 개체 ProviderForLocalSite 속성을 사용하여 로컬 컴퓨터의 SMS 공급자에 연결하고 SWbemServices 개체를 받습니다.

  5. SWbemServices 개체를 사용하여 공급자 개체에 액세스합니다. 자세한 내용은 개체 개요를 참조하세요.

예제

다음 예제에서는 서버에 연결합니다. 그런 다음 해당 서버에 대한 SMS 공급자에 연결을 시도합니다. 일반적으로 이 컴퓨터는 동일한 컴퓨터입니다. 그렇지 않은 경우 SMS_ProviderLocation 올바른 컴퓨터 이름을 제공합니다.

샘플 코드 호출에 대한 자세한 내용은 코드 조각 Configuration Manager 호출을 참조하세요.

Function Connect(server, userName, userPassword)  

    On Error Resume Next  

    Dim net  
    Dim localConnection  
    Dim swbemLocator  
    Dim swbemServices  
    Dim providerLoc  
    Dim location  

    Set swbemLocator = CreateObject("WbemScripting.SWbemLocator")  

    swbemLocator.Security_.AuthenticationLevel = 6 'Packet Privacy.  

    ' If the server is local, do not supply credentials.  
    Set net = CreateObject("WScript.NetWork")   
    If UCase(net.ComputerName) = UCase(server) Then  
        localConnection = true  
        userName = ""  
        userPassword = ""  
        server = "."  
    End If  

    ' Connect to the server.  
    Set swbemServices= swbemLocator.ConnectServer _  
            (server, "root\sms",userName,userPassword)  
    If Err.Number<>0 Then  
        Wscript.Echo "Couldn't connect: " + Err.Description  
        Connect = null  
        Exit Function  
    End If  

    ' Determine where the provider is and connect.  
    Set providerLoc = swbemServices.InstancesOf("SMS_ProviderLocation")  

        For Each location In providerLoc  
            If location.ProviderForLocalSite = True Then  
                Set swbemServices = swbemLocator.ConnectServer _  
                 (location.Machine, "root\sms\site_" + _  
                    location.SiteCode,userName,userPassword)  
                If Err.Number<>0 Then  
                    Wscript.Echo "Couldn't connect:" + Err.Description  
                    Connect = Null  
                    Exit Function  
                End If  
                Set Connect = swbemServices  
                Exit Function  
            End If  
        Next  
    Set Connect = null ' Failed to connect.  
End Function  

다음 샘플에서는 powerShell을 사용하여 원격 서버에 연결하고 SMS 연결을 시도합니다.

$siteCode = ''
$siteServer = 'server.domain'

$credentials = Get-Credential
$username = $credentials.UserName

# The connector does not understand a PSCredential. The following command will pull your PSCredential password into a string.
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($credentials.Password))

$NameSpace = "root\sms\site_$siteCode"
$SWbemLocator = New-Object -ComObject "WbemScripting.SWbemLocator"
$SWbemLocator.Security_.AuthenticationLevel = 6
$connection = $SWbemLocator.ConnectServer($siteServer,$Namespace,$username,$password)

코드 컴파일

이 C# 예제에는 다음이 필요합니다.

설명

샘플 메서드에는 다음과 같은 매개 변수가 있습니다.

매개 변수 형식 설명
connection -관리: WqlConnectionManager
- VBScript: SWbemServices
SMS 공급자에 대한 유효한 연결입니다.
taskSequence -관리: IResultObject
-Vbscript: SWbemObject
유효한 작업 순서(SMS_TaskSequence)입니다.
taskSequenceXML -관리: String
-Vbscript: String
유효한 작업 순서 XML입니다.

강력한 프로그래밍

오류 처리에 대한 자세한 내용은 Configuration Manager 오류 정보를 참조하세요.

.NET Framework 보안

스크립트를 사용하여 사용자 이름과 암호를 전달하는 것은 보안 위험이며 가능한 경우 피해야 합니다.

앞의 예제에서는 인증을 패킷 개인 정보로 설정합니다. 이는 동일한 관리되는 SMS 공급자입니다.

Configuration Manager 애플리케이션 보안에 대한 자세한 내용은 역할 기반 관리 Configuration Manager 참조하세요.

참고 항목

SMS 공급자 기본 사항
WMI를 사용하여 Configuration Manager 컨텍스트 한정자를 추가하는 방법
Windows 관리 계측