Server.Roles Server.Roles Server.Roles Property

Definition

Represents a collection of ServerRole objects. Each ServerRole object represents a role defined on the instance of SQL Server.

public:
 property Microsoft::SqlServer::Management::Smo::ServerRoleCollection ^ Roles { Microsoft::SqlServer::Management::Smo::ServerRoleCollection ^ get(); };
[Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcObject(Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcContainerRelationship.ObjectContainer, Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcContainerCardinality.ZeroToAny, typeof(Microsoft.SqlServer.Management.Smo.ServerRole))]
public Microsoft.SqlServer.Management.Smo.ServerRoleCollection Roles { get; }
Public ReadOnly Property Roles As ServerRoleCollection
Property Value

A ServerRoleCollection object that represents all the roles defined on the instance of SQL Server.

Examples

Visual Basic

'Connect to the local, default instance of SQL Server.  
Dim srv As Server  
srv = New Server  
'Display the fixed server roles.  
Dim sr As ServerRole  
For Each sr In srv.Roles  
   Console.WriteLine(sr.Name)  
Next  

PowerShell

$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")  
foreach ($sr in $srv.Roles)  
{  
   Write-Host $sr.Name  
}  

Remarks

The Roles property points to the ServerRoleCollection object. You can use the collection to reference the fixed server roles the instance of SQL Server.

Applies to