How to Delete a PXE Service Point Role
Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2
You delete the PXE service point role, in Microsoft System Center Configuration Manager 2007, by deleting the role's SMS_SCI_SysResUse Server WMI Class object.
Note
If the PXE service point is online, you must ensure that there are no packages on the PXE distribution point.
To delete a PXE service point role
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
Get the SMS_SCI_SysResUse Server WMI Class object for the PXE service point role.
Check SMS_PackageStatusDistPointsSummarizer Server WMI Class for package instances on the distribution point. If there are any, and the PXE service point is online, remove them before deleting the PXE service point.
Delete the PXE service point SMS_SCI_SysResUse object.
Example
The following example method deletes the PXE service point identified by the site code and network abstraction layer (NAL) path.
Note
This example method will fail if there are assigned packages on the PXE distribution point. Your code should, therefore, check for assigned packages on the PXE distribution point, before calling this sample.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
public void DeletePxeRole(
WqlConnectionManager connection,
string siteCode,
string nalPath)
{
bool roleFound = false;
try
{
// Get the PXE service point role.
string query = string.Format(
CultureInfo.InvariantCulture,
@"SELECT * from SMS_SCI_SysResUse where SiteCode='{0}' AND FileType=2 AND RoleName='SMS Pxe Service Point'AND NALPath='{1}'",
siteCode,
nalPath.Replace(@"\", @"\\"));
IResultObject resultObjs = connection.QueryProcessor.ExecuteQuery(query);
IResultObject resultObj = null;
foreach (IResultObject pxeSiteRole in resultObjs)
{
roleFound = true;
Console.WriteLine("Trying to delete: " + pxeSiteRole["RoleName"].StringValue);
int pxeRoleState = -1;
int blockingPackages = -1;
// Get the PXE role state.
string querySummarizer = string.Format(
CultureInfo.InvariantCulture,
@"SELECT * FROM SMS_SiteSystemSummarizer Where SiteCode=""{0}"" And SiteSystem=""{1}"" And Role=""SMS PXE Service Point""",
pxeSiteRole["SiteCode"].StringValue,
pxeSiteRole.ConnectionManager.EscapeQueryString(pxeSiteRole["NalPath"].StringValue, ConnectionManagerBase.EscapeQuoteType.DoubleQuote));
resultObj = connection.QueryProcessor.ExecuteQuery(querySummarizer);
foreach (IResultObject item in resultObj)
{
pxeRoleState = item["AvailabilityState"].IntegerValue;
break;
}
// Get any blocking packages.
string sharePath = pxeSiteRole["NetworkOSPath"].StringValue + "\\SMSPXEIMAGES$\\";
query = string.Format(
CultureInfo.InvariantCulture,
@"SELECT Count(*) FROM SMS_PackageStatusDistPointsSummarizer Where SiteCode=""{0}"" And ServerNALPath = ""{1}""",
pxeSiteRole["SiteCode"].StringValue,
pxeSiteRole.ConnectionManager.EscapeQueryString(nalPath, ConnectionManagerBase.EscapeQuoteType.DoubleQuote));
resultObj = pxeSiteRole.ConnectionManager.QueryProcessor.ExecuteQuery(query);
foreach (IResultObject item in resultObj)
{
blockingPackages = item["Count"].IntegerValue;
break;
}
// if (PXE Role State is Online) and (On PXE DP Package Count > 0)
if ((pxeRoleState == 1) && (blockingPackages > 0))
{
Console.WriteLine("Remove all packages before deleting the PXE role");
throw new ApplicationException("Remove all packages before deleting the PXE role");
}
else
{
pxeSiteRole.Delete();
Console.WriteLine("Deleted");
}
}
}
catch (SmsException e)
{
Console.WriteLine("Failed to delete PXE service point role: " + e.Message);
throw;
}
finally
{
if (roleFound != true)
{
Console.WriteLine("No matching PXE service points were found");
}
}
}
The example method has the following parameters:
Parameter |
Type |
Description |
connection |
Managed: WqlConnectionManager |
A valid connection to the SMS Provider. |
siteCode |
Managed: String |
The Configuration Manager site code. |
nalPath |
Managed: String |
The NAL path to the PXE service point For example |
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
System.Globalization
System.Localization
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 About Securing Configuration Manager Applications.
See Also
Concepts
SMS_SCI_SysResUse Server WMI Class
About Operating System Deployment Site Role Configuration
Configuration Manager Operating System Deployment
Configuration Manager Programming Fundamentals
Configuration Manager Site Control File
Operating System Deployment Site Role Configuration
How to Read and Write to the Configuration Manager Site Control File by Using Managed Code
How to Read and Write to the Configuration Manager Site Control File by Using WMI