Export (0) Print
Expand All

AffinityInfo.Cpus Property

The Cpus member is a collection that represents the CPU settings for all CPUs on an Instance of SQL Server.

Namespace:  Microsoft.SqlServer.Management.Smo
Assembly:  Microsoft.SqlServer.Smo (in Microsoft.SqlServer.Smo.dll)

public CpuCollection Cpus { get; }

Property Value

Type: Microsoft.SqlServer.Management.Smo.CpuCollection
Returns a CPUCollection.

Access to the Cpus collection is provided though the [T:Microsoft.SqlServer.Management.Smo.AffinityInfo.] member of the Server object.

This example shows you how to create and display the CPU information for all CPUs on the local instance of SQL Server.

using System;
using Microsoft.SqlServer.Management.Smo;

namespace samples
{
    class Program
    {
        static void Main(string[] args)
        {
            Server dbServer = new Server("(local)");

            dbServer.Refresh();

            Console.WriteLine("Total CPUs:       {0}\n", dbServer.AffinityInfo.Cpus.Count);

            foreach (Cpu cpu in dbServer.AffinityInfo.Cpus)
            {
                Console.WriteLine("cpu.ID:           {0}\n" + 
                                  "cpu.GroupID:      {1}\n" +
                                  "cpu.AffinityMask: {2}\n" +
                                  "cpu.NumaNodeID:   {3}\n",
                                  cpu.ID, 
                                  cpu.GroupID,
                                  cpu.AffinityMask,
                                  cpu.NumaNodeID);
            }
        }
    }
}

Powershell

#Create the server. 
$dbServer = new-Object Microsoft.SqlServer.Smo.Server("(local)")
$dbServer.Refresh()

Write-Host "Total CPUs:       Microsoft.SqlServer.Smo`n, $dbServer.AffinityInfo.Cpus.Count"

Foreach ($cpu in $dbServer.AffinityInfo.Cpus)
{
   Write-Host $cpu
}
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft