Skip to content

Restore-DatabaseSecurity

SYNOPSIS

Restore security settings for a SQL Server database.

SYNTAX

Restore-DatabaseSecurity [[-SQLDb] <String>] [[-SQLserver] <String>] [[-UserName] <String>] [[-Type] <String>]
 [[-RoleName] <String>] [[-DefaultSchema] <String>] [[-authentication_type_desc] <String>]

DESCRIPTION

This function restores security settings for a SQL Server database based on the provided parameters. It checks for the existence of users/groups, creates or maps them as needed, assigns roles, and handles contained or non-contained databases.

EXAMPLES

EXAMPLE 1

Restore-DatabaseSecurity -SQLServer "SQLInstance1" -SQLDb "TestDB" -Username "JohnDoe" -RoleName "db_datareader" -authentication_type_desc "Database"

Restores the security settings for the "TestDB" database on "SQLInstance1" by assigning the "db_datareader" role to the "JohnDoe" user.

EXAMPLE 2

Restore-DatabaseSecurity -SQLServer "SQLInstance2" -SQLDb "ProdDB" -Username "JaneSmith" -RoleName "db_owner" -authentication_type_desc "Instance"

Restores the security settings for the "ProdDB" database on "SQLInstance2" by assigning the "db_owner" role to the "JaneSmith" user.

EXAMPLE 3

Restore-DatabaseSecurity -SQLServer "SQLInstance3" -SQLDb "FinanceDB" -Username "Domain\\FinanceGroup" -RoleName "db_datawriter" -authentication_type_desc "Windows"

Restores the security settings for the "FinanceDB" database on "SQLInstance3" by assigning the "db_datawriter" role to the "Domain\\FinanceGroup" group.

PARAMETERS

-SQLDb

The name of the database for which security settings will be restored.

Type: String
Parameter Sets: (All)
Aliases:

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

-SQLserver

The name of the SQL Server instance (preferably the FQDN).

Type: String
Parameter Sets: (All)
Aliases:

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

-UserName

The name of the user, group, or role to be restored.

Type: String
Parameter Sets: (All)
Aliases:

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

-Type

{{ Fill Type Description }}

Type: String
Parameter Sets: (All)
Aliases:

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

-RoleName

The name of the role to assign to the user.

Type: String
Parameter Sets: (All)
Aliases:

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

-DefaultSchema

{{ Fill DefaultSchema Description }}

Type: String
Parameter Sets: (All)
Aliases:

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

-authentication_type_desc

The type of authentication for the user (e.g., Instance, Database, Windows).

Type: String
Parameter Sets: (All)
Aliases:

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

INPUTS

OUTPUTS

NOTES