Get‑SqlDscDatabasePermission - dsccommunity/SqlServerDsc GitHub Wiki

SYNOPSIS

Returns the current permissions for the database principal.

SYNTAX

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

DESCRIPTION

Returns the current permissions for the database principal.

EXAMPLES

EXAMPLE 1

$serverInstance = Connect-SqlDscDatabaseEngine
Get-SqlDscDatabasePermission -ServerObject $serverInstance -DatabaseName 'MyDatabase' -Name 'MyPrincipal'

Get the permissions for the principal 'MyPrincipal'.

EXAMPLE 2

$serverInstance = Connect-SqlDscDatabaseEngine
Get-SqlDscDatabasePermission -ServerObject $serverInstance -DatabaseName 'MyDatabase' -Name 'MyPrincipal' -Refresh

Get the permissions for the principal 'MyPrincipal'. The database's principal collections are refreshed before testing if the principal exists.

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

-Name

Specifies the name of the database principal for which the permissions are returned.

Type: String
Parameter Sets: (All)
Aliases:

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

-Refresh

Specifies that the database's principal collections (Users, Roles, and ApplicationRoles) should be refreshed before testing if the principal exists. This is helpful when principals could have been modified outside of the ServerObject, for example through T-SQL. But on databases with a large amount of principals 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

OUTPUTS

[Microsoft.SqlServer.Management.Smo.DatabasePermissionInfo[]]

NOTES

This command excludes fixed roles like db_datareader by default, and will always return $null 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. In such case the command will return $null. If specifying -ErrorAction 'Stop' the command will throw an error if the database or database principal is missing.

RELATED LINKS

⚠️ **GitHub.com Fallback** ⚠️