トレーニング
モジュール
CIM と WMI を使用して構成情報を照会する - Training
このモジュールでは、クラスを含む名前空間の構造と、クラスのインスタンスを照会する方法について説明します。 アドホック接続と CIM セッションを使用してリモート コンピューターにクエリを実行する方法について説明します。
このブラウザーはサポートされなくなりました。
Microsoft Edge にアップグレードすると、最新の機能、セキュリティ更新プログラム、およびテクニカル サポートを利用できます。
ローカルまたはリモートの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コンテキスト修飾子を追加する方法」を参照してください。
認証レベルをパケット プライバシーに設定します。
SWbemLocator オブジェクト ConnectServer メソッドを使用して、SMS プロバイダーへの接続を設定します。 資格情報は、リモート コンピューターの場合にのみ指定します。
SMS_ProviderLocation オブジェクト ProviderForLocalSite プロパティを使用して、ローカル コンピューターの SMS プロバイダーに接続し、SWbemServices オブジェクトを受け取ります。
プロバイダー オブジェクトにアクセスするには 、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 エラーについて」を参照してください。
スクリプトを使用してユーザー名とパスワードを渡すことはセキュリティ上のリスクであり、可能な限り避ける必要があります。
前の例では、認証をパケット プライバシーに設定します。 これは、同じマネージド SMS プロバイダーです。
Configuration Manager アプリケーションのセキュリティ保護の詳細については、「ロールベースの管理Configuration Manager」を参照してください。
SMS プロバイダーの基礎
WMI を使用してConfiguration Manager コンテキスト修飾子を追加する方法
Windows Management Instrumentation
トレーニング
モジュール
CIM と WMI を使用して構成情報を照会する - Training
このモジュールでは、クラスを含む名前空間の構造と、クラスのインスタンスを照会する方法について説明します。 アドホック接続と CIM セッションを使用してリモート コンピューターにクエリを実行する方法について説明します。
ドキュメント
マネージド コードを使用して SMS プロバイダーに接続する - Configuration Manager
SMS プロバイダーに接続するには、WqlConnectionManager.Connect を使用します。
マネージド SMS プロバイダーの基礎 - Configuration Manager
マネージド SMS プロバイダー ライブラリは、System.Management クラスをラップし、Configuration Manager中心のオブジェクト モデルを提供し、Configuration Managerサイト コントロール ファイルにアクセスするためのラッパーを提供する.NET Framework ライブラリです。
SMS プロバイダーの基礎 - Configuration Manager
SMS プロバイダーを使用して、Configuration Manager データにアクセスして変更します。 WMI またはマネージド クラスを介してアクセスできる WMI プロバイダーです。
WMI プロバイダーの基礎 - Configuration Manager
Windows スクリプト ホスト ベースのアプリケーションとスクリプトは、WMI へのプログラミング インターフェイスを定義する WMI オブジェクト モデルを使用して、Windows Management Instrumentation (WMI) で機能します。