Skip to content

Set SqlDscDatabasePermission

dscbot edited this page Mar 3, 2024 · 2 revisions

Set-SqlDscDatabasePermission

SYNOPSIS

Set permission for a database principal.

SYNTAX

Set-SqlDscDatabasePermission [-ServerObject] <Server> [-DatabaseName] <String> [-Name] <String>
 [-State] <String> [-Permission] <DatabasePermissionSet> [-WithGrant] [-Force]
 [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

Set permission for a database principal.

EXAMPLES

EXAMPLE 1

$serverInstance = Connect-SqlDscDatabaseEngine

$setPermission = [Microsoft.SqlServer.Management.Smo.DatabasePermissionSet] @{ Connect = $true Update = $true }

Set-SqlDscDatabasePermission -ServerObject $serverInstance -DatabaseName 'MyDatabase' -Name 'MyPrincipal' -State 'Grant' -Permission $setPermission

Sets the permissions for the principal 'MyPrincipal'.

PARAMETERS

-DatabaseName

Specifies the database name.

Type: String
Parameter Sets: (All)
Aliases:

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

-Force

Specifies that the permissions should be set 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 database principal for which the permissions are set.

Type: String
Parameter Sets: (All)
Aliases:

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

-Permission

Specifies the permissions.

Type: DatabasePermissionSet
Parameter Sets: (All)
Aliases:

Required: True
Position: 5
Default value: None
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

-State

Specifies the state of the permission.

Type: String
Parameter Sets: (All)
Aliases:

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

-WithGrant

Specifies that the principal should also be granted the right to grant other principals the same permission. This parameter is only valid when parameter State is set to Grant or Revoke. When the parameter State is set to Revoke the right to grant will also be revoked, and the revocation will cascade.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

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

None.

NOTES

This command excludes fixed roles like db_datareader by default, and will always throw a non-terminating error if a fixed role is specified as Name.

If specifying -ErrorAction 'SilentlyContinue' then the command will silently ignore if the database (parameter DatabaseName) is not present or the database principal is not present. If specifying -ErrorAction 'Stop' the command will throw an error if the database or database principal is missing.

RELATED LINKS

Home

Commands

Resources

Usage

Clone this wiki locally