英語で読む

次の方法で共有


WMI を使用してConfiguration Managerで SMS プロバイダーに接続する方法

ローカルまたはリモートのConfiguration Manager サイト サーバーの SMS プロバイダーに接続する前に、まずサイト サーバーの SMS プロバイダーを見つける必要があります。 SMS プロバイダーは、使用しているConfiguration Manager サイト サーバーに対してローカルまたはリモートにすることができます。 Windows Management Instrumentation (WMI) クラスSMS_ProviderLocationはすべてのConfiguration Manager サイト サーバーに存在し、1 つのインスタンスには、使用している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# の例では、次のものが必要です。

Comments

サンプル メソッドには、次のパラメーターがあります。

パラメーター 説明
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 Management Instrumentation