アプリケーションは、SMS_Collection サーバー WMI クラスとクラス プロパティを使用して、Configuration Manager内のコレクションを削除できます。
重要
Configuration Managerオブジェクトを削除するときは、注意が必要です。
複数のコレクションを削除する場合は、データベース操作時に削除に関連する変更を管理できるように、一度に 1 つずつ削除することをお勧めします。
コレクションは、パッケージ、プログラム、広告と密接に関連付けられています。 詳細については、「 ソフトウェア配布の概要」を参照してください。
これらの例では、次の値が必要です。
Windows Management Instrumentation (WMI) 接続オブジェクト。
既存のコレクション ID。
次のコードは、Visual Basic でのサブルーチン呼び出しの例です。
Call DeleteCollection(swbemServices,"ABC00010")
次のコードは、C# でのメソッド呼び出しの例です。
DeleteCollection(WMIConnection,"ABC00010")
コレクションを削除するには
SMS プロバイダーへの接続を設定します。 詳細については、「 SMS プロバイダーの基礎」を参照してください。
指定されたコレクション ID を使用して、特定のコレクション インスタンスを取得します。
delete メソッドを使用してコレクションを削除します。
例
次のメソッド例では、コレクションを削除します。
サンプル コードの呼び出しについては、「Configuration Manager コード スニペットの呼び出し」を参照してください。
' Setup a connection to the local provider.
Set swbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set swbemServices= swbemLocator.ConnectServer(".", "root\sms")
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)
Exit For
End If
Next
Call DeleteCollection(swbemServices,"ABC00010")
Sub DeleteCollection(connection, collectionIDToDelete)
' Get the specific collection instance to delete.
Set collectionToDelete = connection.Get("SMS_Collection.CollectionID='" & collectionIDToDelete & "'")
' Delete the collection.
collectionToDelete.Delete_
' Display change information.
Wscript.Echo "Deleted collection: " & collectionIDToDelete
End Sub
public void DeleteCollection(WqlConnectionManager connection, string collectionIDToDelete)
{
// Note: On delete, the provider cleans up the SMS_CollectionSettings and SMS_CollectToSubCollect objects.
try
{
// Get the specific collection instance to delete.
IResultObject collectionToDelete = connection.GetInstance(@"SMS_Collection.CollectionID='" + collectionIDToDelete + "'");
// Delete the collection.
collectionToDelete.Delete();
// Output the ID of the deleted collection.
Console.WriteLine("Deleted collection: " + collectionIDToDelete);
}
catch (SmsException ex)
{
Console.WriteLine("Failed to delete collection. Error: " + ex.Message);
throw;
}
}
このメソッドの例には、次のパラメーターがあります。
パラメーター | 型 | 説明 |
---|---|---|
connection |
-管理: WqlConnectionManager - VBScript: SWbemServices |
SMS プロバイダーへの有効な接続。 |
collectionIDToDelete |
-管理: String -Vbscript: String |
8 文字を含む一意の自動生成 ID。 詳細については、「SMS_Collection サーバー WMI クラス」のプロパティを参照してくださいCollectionID 。 |
コードのコンパイル
C# の例では、次のものが必要です。
名前空間
System
System.Collections.Generic
System.ComponentModel
Microsoft。ConfigurationManagement.ManagementProvider
Microsoft。ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
堅牢なプログラミング
エラー処理の詳細については、「Configuration Manager エラーについて」を参照してください。
.NET Framework のセキュリティ
Configuration Manager アプリケーションのセキュリティ保護の詳細については、「ロールベースの管理Configuration Manager」を参照してください。
関連項目
SMS_Collection サーバー WMI クラス
コレクションを削除する ソフトウェア配布の概要展開についてオブジェクトの概要マネージド コードを使用してConfiguration Manager プロバイダーに接続する方法
WMI を使用してConfiguration Manager プロバイダーに接続する方法