次の方法で共有


How to Get and Set the Assigned Site for a Configuration Manager Client

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 set the assigned site for a Configuration Manager 2007 client by calling the SMSClientClass object SetAssignedSite method. You get the current site assigned for a client by calling the SMSClientClass object GetAssignedSite method.

To get and set the assigned site for a Configuration Manager client

  1. Get the Configuration Manager client configuration object (SMSClientClass).

  2. From the SMSClientClass object, call GetAssignedSite to get the client's assigned site.

  3. From the SMSClientClass object, call SetAssignedSite to set the client's assigned site.

Example

The following example method sets the assigned site for a Configuration Manager client by using the SMSClientClass object SetAssignedSite method. It also displays the current and updated assigned site using GetAssignedSite.

For information about calling the sample code, see How to Call Configuration Manager COM Automation Objects.

Sub SetAssignedSite (newSite)

    On Error Resume Next

    Dim oSMSClient

    Set oSMSClient = CreateObject ("Microsoft.SMS.Client")

    If Err.Number <>0 Then 
    wscript.echo "Could not create SMS Client Object - quitting"
    Exit Sub
    End If
    
    ' Set the assigned site.
    WScript.Echo "Current site: " & oSMSClient.GetAssignedSite
    oSMSClient.SetAssignedSite newSite,0
    Wscript.Echo "Assigned site is now: " & oSMSClient.GetAssignedSite

    Set oSMSClient=Nothing
End Sub
public void SetAssignedSite(string site)
{
    try
    {
        SmsClientClass client = new SmsClientClass();

        Console.WriteLine ("Current site: " + client.GetAssignedSite());

        client.SetAssignedSite(site,0);

        Console.WriteLine ("Assigned site is now :" + client.GetAssignedSite());
    }
    catch (COMException e)
    {
        Console.WriteLine("Failed to set assigned site: " + e.Message);
        throw;
    }
}

The example method has the following parameters:

Parameter Type Description

newSite

  • Managed: String

  • VBScript: String

  • The site code for the new assigned site.

Compiling the Code

This C# example requires:

Namespaces

System

System.Collections.Generic

System.Text

System.Runtime.InteropServices

SmsClientLib

Assembly

SmsClientLib

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

About Configuration Manager Client Configuration
Configuration Manager Client Configuration
How to Get and Set the Current Management Point for a Configuration Manager Client
How to Call Configuration Manager COM Automation Objects