To clear a PXE advertisement for a System Center 2012 Configuration Manager resource, you call the SMS_Collection object ClearLastNBSAdvForMachines method.
Clearing PXE advertisement is used to re-advertise a mandatory advertisement that is enabled for a PXE device or assigned to a collection. For information about clearing the PXE advertisement for a collection, see How to Clear a PXE Advertisement For a Configuration Manager Collection.
Clearing a PXE advertisement forces the PXE server to re-evaluate the mandatory advertisement that a PXE device must execute on the next PXE boot. It is most often used when the last advertisement that was executed failed or when the advertisement must be re-run.
To clear a PXE advertisement for a resource
-
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
-
Create the ClearLastNBSAdvForMachines method resource identifier array for the method parameters.
-
Call the ClearLastNBSAdvForMachines method to clear the PXE advertisement for the resource.
Example
The following example clears the PXE advertisement for the resource identified by the resourceID parameter.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Visual Basic Script | Copy Code |
---|---|
Sub ClearPxeAdvertisementResource(connection,resourceID) On Error Resume Next Dim resources Dim InParams ' Set up the Resource array parameter. resources = Array(1) resources(0) = resourceID Set InParams = connection.Get("SMS_Collection").Methods_("ClearLastNBSAdvForMachines").InParameters.SpawnInstance_ InParams.ResourceIDs = resources connection.ExecMethod "SMS_Collection","ClearLastNBSAdvForMachines", InParams if Err.number <> 0 Then WScript.Echo "Failed to clear PXE advertisement for resource: " & resourceID Exit Sub End If End Sub |
C# | Copy Code |
---|---|
public void ClearPxeAdvertisementResource(WqlConnectionManager connection, int resourceID) { try { List<int> resourceIDs = new List<int>(); Dictionary<string, object> inParams = new Dictionary<string, object>(); resourceIDs.Add(resourceID); inParams.Add("ResourceIDs", resourceIDs.ToArray()); IResultObject outParams = connection.ExecuteMethod("SMS_Collection","ClearLastNBSAdvForMachines",inParams); if (outParams == null || outParams["StatusCode"].IntegerValue != 0) { Console.WriteLine ("Failed to clear PXE advertisement for resource " + resourceID); return; } } catch (SmsException e) { Console.WriteLine("Failed to PXE advertisement " + e.Message); } } |
The example method has the following parameters:
Parameter |
Type |
Description |
connection |
|
A valid connection to the SMS Provider. |
resourceID |
|
The resource identifier. You can obtain this from the SMS_Resource class ResourceId property. |
Compiling the Code
The C# example has the following compilation requirements:
Namespaces
System
System.Collections.Generic
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
microsoft.configurationmanagement.managementprovider
adminui.wqlqueryengine
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
Security
For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.