How to Clear a PXE Advertisement for a Configuration Manager Resource
Updated: November 1, 2013
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
To clear a PXE advertisement for a System Center 2012 R2 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.
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
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); } }
Compiling the Code
The C# example has the following compilation requirements:
System
System.Collections.Generic
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
microsoft.configurationmanagement.managementprovider
adminui.wqlqueryengine
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
.NET Framework Security
For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.
The example method has the following parameters:
Parameter
Type
Description
connection
Managed: WqlConnectionManager
VBScript: SWbemServices
A valid connection to the SMS Provider.
resourceID
Managed: Integer
VBScript: Integer
The resource identifier. You can obtain this from the SMS_Resource class ResourceId property.