必要なサイト コントロール ファイルの設定を変更して、Configuration Managerでネットワーク検出の設定を構成します。
ネットワーク探索を構成するには
SMS プロバイダーへの接続を設定します。
クラスを使用して、サイト コントロール ファイルの [ネットワーク検出] セクションに接続します
SMS_SCI_Component
。使用可能なプロパティの配列をループして、必要に応じて変更を加えます。
サイト コントロール ファイルに変更をコミットします。
クラスを使用して、サイト コントロール ファイルの [ネットワーク検出] セクションに接続します
SMS_SCI_Configuration
。使用可能なプロパティの配列をループして、必要に応じて変更を加えます。
サイト コントロール ファイルに変更をコミットします。
例
次の例では、 クラスと SMS_SCI_Configuration
クラスを使用してSMS_SCI_Component
サイト コントロール ファイルに接続し、プロパティを変更することで、ネットワーク検出の設定を設定します。
注:
ネットワーク探索は、コンポーネントを有効にするために、 プロパティと SMS_SCI_Configuration
クラス プロパティの両方をSMS_SCI_Component
設定する必要がある点で、通常は異なります。
smple コードの呼び出しについては、「Configuration Manager コード スニペットの呼び出し」を参照してください。
Sub ConfigureNetworkDiscoverySettings(swbemServices, _
swbemContext, _
siteCode, _
enableDisableDiscovery)
' Load site control file and get the SMS_SCI_Component, SMS_NETWORK_DISCOVERY section.
swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext
' Get the SMS_SCI_Component, SMS_NETWORK_DISCOVERY section of the site control file.
Query = "SELECT * FROM SMS_SCI_Component " & _
"WHERE ComponentName = 'SMS_NETWORK_DISCOVERY' " & _
"AND SiteCode = '" & siteCode & "'"
' Get the SMS_NETWORK_DISCOVERY properties.
Set SCIComponentSet = swbemServices.ExecQuery(Query, ,wbemFlagForwardOnly Or wbemFlagReturnImmediately, swbemContext)
' Only one instance is returned from the query.
For Each SCIComponent In SCIComponentSet
' Display the server name.
wscript.echo "Server: " & SCIComponent.Name
' Loop through the array of embedded SMS_EmbeddedProperty instances.
For Each vProperty In SCIComponent.Props
' Setting: Discovery Enabled
If vProperty.PropertyName = "Discovery Enabled" Then
wscript.echo " "
wscript.echo vProperty.PropertyName
wscript.echo "Current value: " & vProperty.Value1
' Modify the value.
vProperty.Value1 = enableDisableDiscovery
wscript.echo "New value: " & enableDisableDiscovery
End If
Next
' Update the component in your copy of the site control file. Get the path
' to the updated object, which could be used later to retrieve the instance.
Set SCICompPath = SCIComponent.Put_(wbemChangeFlagUpdateOnly, swbemContext)
Next
' Get the SMS_SCI_Configuration, SMS_NETWORK_DISCOVERY section of the site control file.
Query = "SELECT * FROM SMS_SCI_Configuration " & _
"WHERE ItemName = 'SMS_NETWORK_DISCOVERY' " & _
"AND SiteCode = '" & siteCode & "'"
' Get the SMS_NETWORK_DISCOVERY properties.
Set SCIComponentSet = swbemServices.ExecQuery(Query, ,wbemFlagForwardOnly Or wbemFlagReturnImmediately, swbemContext)
' Only one instance is returned from the query.
For Each SCIComponent In SCIComponentSet
' Loop through the array of embedded SMS_EmbeddedProperty instances.
For Each vProperty In SCIComponent.Props
' Setting: Discovery Enabled
If vProperty.PropertyName = "Discovery Enabled" Then
wscript.echo " "
wscript.echo vProperty.PropertyName
wscript.echo "Current value: " & vProperty.Value1
' Modify the value.
vProperty.Value1 = enableDisableDiscovery
wscript.echo "New value: " & enableDisableDiscovery
End If
Next
' Update the component in your copy of the site control file. Get the path
' to the updated object, which could be used later to retrieve the instance.
Set SCICompPath = SCIComponent.Put_(wbemChangeFlagUpdateOnly, swbemContext)
Next
' Commit the change to the actual site control file.
Set InParams = swbemServices.Get("SMS_SiteControlFile").Methods_("CommitSCF").InParameters.SpawnInstance_
InParams.SiteCode = siteCode
swbemServices.ExecMethod "SMS_SiteControlFile", "CommitSCF", InParams, , swbemContext
End Sub
public void ConfigureNetworkDiscoverySettings(WqlConnectionManager connection,
string siteCode,
string serverName,
string enableDisableDiscovery)
{
try
{
// Connect to SMS_SCI_Component, SMS_NETWORK_DISCOVERY section of the site control file.
IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_Component.FileType=2,ItemType='Component',SiteCode='" + siteCode + "',ItemName='SMS_NETWORK_DISCOVERY|" + serverName + "'");
// Create temporary copy of the embedded properties.
Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties;
// Enumerate through the embedded properties and makes changes as needed.
foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties)
{
// Setting: Discovery Enabled
if (kvp.Value.PropertyList["PropertyName"] == "Discovery Enabled")
{
Console.WriteLine();
Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
Console.WriteLine("Current value: " + kvp.Value.PropertyList["Value1"]);
// Change value using the newDiscoveryEnabled value passed in.
embeddedProperties["Discovery Enabled"]["Value1"].StringValue = enableDisableDiscovery;
Console.WriteLine("New value : " + enableDisableDiscovery);
}
}
// Store the settings that have changed.
siteDefinition.EmbeddedProperties = embeddedProperties;
// Save the settings.
siteDefinition.Put();
}
catch (SmsException ex)
{
Console.WriteLine();
Console.WriteLine("Failed. Error: " + ex.InnerException.Message);
}
try
{
// Connect to SMS_SCI_Configuration, SMS_NETWORK_DISCOVERY section of the site control file.
IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_Configuration.FileType=2,ItemType='Configuration',SiteCode='" + siteCode + "',ItemName='SMS_NETWORK_DISCOVERY'");
// Create temporary copy of the embedded properties.
Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties;
// Enumerate through the embedded properties and makes changes as needed.
foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties)
{
// Setting: Discovery Enabled
if (kvp.Value.PropertyList["PropertyName"] == "Discovery Enabled")
{
Console.WriteLine();
Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
Console.WriteLine("Current value: " + kvp.Value.PropertyList["Value1"]);
// Change value using the newDiscoveryEnabled value passed in.
embeddedProperties["Discovery Enabled"]["Value1"].StringValue = enableDisableDiscovery;
Console.WriteLine("New value : " + enableDisableDiscovery);
}
}
// Store the settings that have changed.
siteDefinition.EmbeddedProperties = embeddedProperties;
//Save the settings.
siteDefinition.Put();
}
catch (SmsException ex)
{
Console.WriteLine("Failed. Error: " + ex.InnerException.Message);
throw;
}
}
このメソッドの例には、次のパラメーターがあります。
パラメーター | 型 | 説明 |
---|---|---|
- connection - swbemServices |
-管理: WqlConnectionManager - VBScript: SWbemServices |
SMS プロバイダーへの有効な接続。 |
swbemContext |
-Vbscript: SWbemContext |
有効なコンテキスト オブジェクト。 詳細については、「WMI を使用してConfiguration Managerコンテキスト修飾子を追加する方法」を参照してください。 |
siteCode |
-管理: String -Vbscript: String |
サイト コード。 |
serverName |
-管理: String -Vbscript: String |
サーバー名。 |
enableDisableDiscovery |
-管理: String -Vbscript: String |
検出方法を有効または無効にする値。 無効- false 有効- true |
コードのコンパイル
この C# の例では、次のものが必要です。
名前空間
System
System.Collections.Generic
System.text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
堅牢なプログラミング
エラー処理の詳細については、「Configuration Manager エラーについて」を参照してください。
.NET Framework のセキュリティ
Configuration Manager アプリケーションのセキュリティ保護の詳細については、「ロールベースの管理Configuration Manager」を参照してください。
関連項目
サイトコントロールファイルのConfiguration Managerについて
マネージド コードを使用してConfiguration Manager サイト コントロール ファイルの読み取りと書き込みを行う方法
WMI を使用してConfiguration Manager サイト コントロール ファイルの読み取りと書き込みを行う方法
SMS_SCI_Component サーバー WMI クラス
スケジュールについて スケジュールトークンをCreateする方法