commands

^

Remove-DbaServerRoleMember

Author Mikey Bronowski (@MikeyBronowski), bronowski.it
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Remove-DbaServerRoleMember on GitHub.
Want to see the Bill Of Health for this command? Check out Remove-DbaServerRoleMember.

Synopsis

Removes login(s) from a server-level role(s) for each instance(s) of SQL Server.

Description

Removes login(s) from a server-level role(s) for each instance(s) of SQL Server.

Syntax

Remove-DbaServerRoleMember
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-ServerRole] <String[]>]
    [[-Login] <String[]>]
    [[-Role] <String[]>]
    [[-InputObject] <Object[]>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Remove-DbaServerRoleMember -SqlInstance server1 -ServerRole dbcreator -Login login1

Removes login1 from the dbcreator fixed server-level role on the instance server1.

Example: 2
PS C:\> Remove-DbaServerRoleMember -SqlInstance server1, sql2016 -ServerRole customrole -Login login1

Removes login1 from customrole custom server-level role on the instance server1 and sql2016.

Example: 3
PS C:\> Remove-DbaServerRoleMember -SqlInstance server1 -ServerRole customrole -Role dbcreator

Removes customrole custom server-level role from the dbcreator fixed server-level role.

Example: 4
PS C:\> $servers = Get-Content C:\servers.txt
PS C:\> $servers | Remove-DbaServerRoleMember -ServerRole sysadmin -Login login1

Removes login1 from the sysadmin fixed server-level role in every server in C:\servers.txt.

Example: 5
PS C:\> Remove-DbaServerRoleMember -SqlInstance localhost -ServerRole bulkadmin, dbcreator -Login login1

Removes login1 from the bulkadmin and dbcreator fixed server-level roles on the server localhost.

Example: 6
PS C:\> $roles = Get-DbaServerRole -SqlInstance localhost -ServerRole bulkadmin, dbcreator
PS C:\> $roles | Remove-DbaServerRoleMember -Login login1

Removes login1 from the bulkadmin and dbcreator fixed server-level roles on the server localhost.

Example: 7
PS C:\> PS C:\ $logins = Get-Content C:\logins.txt

PS C:\ $srvLogins = Get-DbaLogin -SqlInstance server1 -Login $logins
PS C:\ Remove-DbaServerRoleMember -Login $logins -ServerRole mycustomrole
Removes all the logins found in C:\logins.txt from mycustomrole custom server-level role on server1.

Optional Parameters

-SqlInstance

The target SQL Server instance or instances. This can be a collection and receive pipeline input to allow the function to be executed against multiple SQL Server instances.

Alias
Required False
Pipeline true (ByValue)
Default Value
-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-ServerRole

The server-level role(s) to process.

Alias
Required False
Pipeline false
Default Value
-Login

The login(s) to remove from server-level role(s) specified.

Alias
Required False
Pipeline false
Default Value
-Role

The role(s) to remove from server-level role(s) specified.

Alias
Required False
Pipeline false
Default Value
-InputObject

Enables piped input from Get-DbaServerRole.

Alias
Required False
Pipeline true (ByValue)
Default Value
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts you for confirmation before executing any changing operations within the command.

Alias cf
Required False
Pipeline false
Default Value