Skip to content

New‑SqlDscRole

dscbot edited this page Aug 22, 2025 · 1 revision

SYNOPSIS

Creates a new server role in a SQL Server Database Engine instance.

SYNTAX

New-SqlDscRole [-ServerObject] <Server> [-Name] <String> [[-Owner] <String>] [-Force] [-Refresh]
 [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

This command creates a new server role in a SQL Server Database Engine instance.

EXAMPLES

EXAMPLE 1

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

Creates a new server role named MyCustomRole.

EXAMPLE 2

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | New-SqlDscRole -Name 'MyCustomRole' -Owner 'MyOwner' -Force

Creates a new server role named MyCustomRole with the specified owner without prompting for confirmation.

PARAMETERS

-Force

Specifies that the role should be created without any confirmation.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

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

-Name

Specifies the name of the server role to be created.

Type: String
Parameter Sets: (All)
Aliases:

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

-Owner

Specifies the owner of the server role. If not specified, the role will be owned by the login that creates it.

Type: String
Parameter Sets: (All)
Aliases:

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

-Refresh

Specifies that the ServerObject's roles should be refreshed before creating 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

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

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

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
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

OUTPUTS

[Microsoft.SqlServer.Management.Smo.ServerRole]

NOTES

RELATED LINKS

Home

Commands

Resources

Usage

Clone this wiki locally