Skip to content

Get‑SqlDscRole

dscbot edited this page Dec 5, 2025 · 2 revisions

SYNOPSIS

Get server roles from a SQL Server Database Engine instance.

SYNTAX

Get-SqlDscRole [-ServerObject] <Server> [[-Name] <String>] [-Refresh] 
 [<CommonParameters>]

DESCRIPTION

This command gets one or more server roles from a SQL Server Database Engine instance. If no name is specified, all server roles are returned.

EXAMPLES

EXAMPLE 1

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Get-SqlDscRole

Get all server roles from the instance.

EXAMPLE 2

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Get-SqlDscRole -Name 'MyCustomRole'

Get the server role named MyCustomRole.

PARAMETERS

-Name

Specifies the name of the server role to get. If not specified, all server roles are returned.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Refresh

Specifies that the ServerObject's roles should be refreshed before trying to get the role object. This is helpful when roles could have been modified outside of the ServerObject, for example through T-SQL. But on instances with a large amount of roles it might be better to make sure the ServerObject is recent enough.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ServerObject

Specifies current server connection object.

Type: Server
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

Microsoft.SqlServer.Management.Smo.Server

Accepts input via the pipeline.

OUTPUTS

Microsoft.SqlServer.Management.Smo.ServerRole[]

Returns the server role objects from the instance.

NOTES

RELATED LINKS

Home

Commands

Resources

Usage

Clone this wiki locally