Server.Grant Server.Grant Server.Grant Method

Definition

Grants the specified set of permissions to the specified grantees on the instance of SQL Server.

Overloads

Grant(ServerPermissionSet, String[], Boolean, String) Grant(ServerPermissionSet, String[], Boolean, String) Grant(ServerPermissionSet, String[], Boolean, String)

Grants the specified set of permissions to the grantees and the ability to grant the set of permissions to other users on the instance of SQL Server under an assumed role.

Grant(ServerPermissionSet, String, Boolean, String) Grant(ServerPermissionSet, String, Boolean, String) Grant(ServerPermissionSet, String, Boolean, String)

Grants the specified set of permissions to the grantee and the ability to grant the set of permissions to other users on the instance of SQL Server under an assumed role.

Grant(ServerPermissionSet, String[], Boolean) Grant(ServerPermissionSet, String[], Boolean) Grant(ServerPermissionSet, String[], Boolean)

Grants access to the specified permission to the grantees and the ability to grant access to other users on the instance of SQL Server.

Grant(ServerPermissionSet, String[]) Grant(ServerPermissionSet, String[]) Grant(ServerPermissionSet, String[])

Grants the specified set of permissions to the specified grantees on the instance of SQL Server.

Grant(ServerPermissionSet, String) Grant(ServerPermissionSet, String) Grant(ServerPermissionSet, String)

Grants the specified set of permissions to the specified grantee on the instance of SQL Server.

Grant(ServerPermissionSet, String, Boolean) Grant(ServerPermissionSet, String, Boolean) Grant(ServerPermissionSet, String, Boolean)

Grants access to the specified permission to the grantee and the ability to grant access to other users on the instance of SQL Server.

Remarks

The Grant method has several overloads that give you a choice of whether to grant one or more permission to a single grantee or to several grantees. It also lets you specify whether the grantee has permission to give other users permission, and what role the grantee assumes when taking this action.

Grant(ServerPermissionSet, String[], Boolean, String) Grant(ServerPermissionSet, String[], Boolean, String) Grant(ServerPermissionSet, String[], Boolean, String)

Grants the specified set of permissions to the grantees and the ability to grant the set of permissions to other users on the instance of SQL Server under an assumed role.

public:
 void Grant(Microsoft::SqlServer::Management::Smo::ServerPermissionSet ^ permission, cli::array <System::String ^> ^ granteeNames, bool grantGrant, System::String ^ asRole);
public void Grant (Microsoft.SqlServer.Management.Smo.ServerPermissionSet permission, string[] granteeNames, bool grantGrant, string asRole);
Public Sub Grant (permission As ServerPermissionSet, granteeNames As String(), grantGrant As Boolean, asRole As String)
Parameters
permission
ServerPermissionSet ServerPermissionSet ServerPermissionSet

A ServerPermissionSet object that specifies the permission.

granteeNames
String[]

A String array that specifies a list of grantees to be granted the set of permissions.

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the set of permissions to other users on the instance of SQL Server.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the instance of SQL Server.

If False, the grantee is not given the ability to grant the specified set of permissions to other users on the instance of SQL Server.

asRole
String String String

A String value that specifies the role that the user assumes when granting the specified set of permissions to other users on the instance of SQL Server. Use this parameter for grantees who are members of more than one role.

Examples

Visual Basic

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$arg = [Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint  

$sps = new-object Microsoft.SqlServer.Management.Smo.ServerPermissionSet([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  
$sps.Add([Microsoft.SqlServer.Management.Smo.ServerPermission]::AlterAnyEndpoint)  
$spis = $srv.EnumServerPermissions("vGrantee", $sps)  
Write-Host "=================Before revoke==========================="  
Foreach ($spi In $spis)  
{  
   Write-Host $spi.Grantee "has" $spi.PermissionType " permission."  
}  
Write-Host " "  
$sps.Remove([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  

Grant(ServerPermissionSet, String, Boolean, String) Grant(ServerPermissionSet, String, Boolean, String) Grant(ServerPermissionSet, String, Boolean, String)

Grants the specified set of permissions to the grantee and the ability to grant the set of permissions to other users on the instance of SQL Server under an assumed role.

public:
 void Grant(Microsoft::SqlServer::Management::Smo::ServerPermissionSet ^ permission, System::String ^ granteeName, bool grantGrant, System::String ^ asRole);
public void Grant (Microsoft.SqlServer.Management.Smo.ServerPermissionSet permission, string granteeName, bool grantGrant, string asRole);
Public Sub Grant (permission As ServerPermissionSet, granteeName As String, grantGrant As Boolean, asRole As String)
Parameters
permission
ServerPermissionSet ServerPermissionSet ServerPermissionSet

A ServerPermissionSet object that specifies the permission.

granteeName
String String String

A String value that specifies a grantee to be denied access to the permission.

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the specified set of permissions to other users on the instance of SQL Server.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the instance of SQL Server.

If False, the grantee is not given the ability to grant the specified set of permissions to other users on the instance of SQL Server.

asRole
String String String

A String value that specifies the role that the user assumes when granting the specified set of permissions to other users on the instance of SQL Server. Use this parameter for grantees who are members of more than one role.

Examples

Visual Basic

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$arg = [Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint  

$sps = new-object Microsoft.SqlServer.Management.Smo.ServerPermissionSet([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  
$sps.Add([Microsoft.SqlServer.Management.Smo.ServerPermission]::AlterAnyEndpoint)  
$spis = $srv.EnumServerPermissions("vGrantee", $sps)  
Write-Host "=================Before revoke==========================="  
Foreach ($spi In $spis)  
{  
   Write-Host $spi.Grantee "has" $spi.PermissionType " permission."  
}  
Write-Host " "  
$sps.Remove([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  

Grant(ServerPermissionSet, String[], Boolean) Grant(ServerPermissionSet, String[], Boolean) Grant(ServerPermissionSet, String[], Boolean)

Grants access to the specified permission to the grantees and the ability to grant access to other users on the instance of SQL Server.

public:
 void Grant(Microsoft::SqlServer::Management::Smo::ServerPermissionSet ^ permission, cli::array <System::String ^> ^ granteeNames, bool grantGrant);
public void Grant (Microsoft.SqlServer.Management.Smo.ServerPermissionSet permission, string[] granteeNames, bool grantGrant);
Public Sub Grant (permission As ServerPermissionSet, granteeNames As String(), grantGrant As Boolean)
Parameters
permission
ServerPermissionSet ServerPermissionSet ServerPermissionSet

A ServerPermissionSet object that specifies the permission.

granteeNames
String[]

A String array that specifies a list of grantees to be denied access to the set of permissions.

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the specified set of permissions to other users on the instance of SQL Server.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the instance of SQL Server.

If False, the grantee is not given the ability to grant the specified set of permissions to other users on the instance of SQL Server.

Examples

Visual Basic

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$arg = [Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint  

$sps = new-object Microsoft.SqlServer.Management.Smo.ServerPermissionSet([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  
$sps.Add([Microsoft.SqlServer.Management.Smo.ServerPermission]::AlterAnyEndpoint)  
$spis = $srv.EnumServerPermissions("vGrantee", $sps)  
Write-Host "=================Before revoke==========================="  
Foreach ($spi In $spis)  
{  
   Write-Host $spi.Grantee "has" $spi.PermissionType " permission."  
}  
Write-Host " "  
$sps.Remove([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  

Grant(ServerPermissionSet, String[]) Grant(ServerPermissionSet, String[]) Grant(ServerPermissionSet, String[])

Grants the specified set of permissions to the specified grantees on the instance of SQL Server.

public:
 void Grant(Microsoft::SqlServer::Management::Smo::ServerPermissionSet ^ permission, cli::array <System::String ^> ^ granteeNames);
public void Grant (Microsoft.SqlServer.Management.Smo.ServerPermissionSet permission, string[] granteeNames);
Public Sub Grant (permission As ServerPermissionSet, granteeNames As String())
Parameters
permission
ServerPermissionSet ServerPermissionSet ServerPermissionSet

A ServerPermissionSet object that specifies the permission.

granteeNames
String[]

A String array that lists the grantees to be granted the specified set of permissions on the instance of SQL Server.

Examples

Visual Basic

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$arg = [Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint  

$sps = new-object Microsoft.SqlServer.Management.Smo.ServerPermissionSet([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  
$sps.Add([Microsoft.SqlServer.Management.Smo.ServerPermission]::AlterAnyEndpoint)  
$spis = $srv.EnumServerPermissions("vGrantee", $sps)  
Write-Host "=================Before revoke==========================="  
Foreach ($spi In $spis)  
{  
   Write-Host $spi.Grantee "has" $spi.PermissionType " permission."  
}  
Write-Host " "  
$sps.Remove([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  

Grant(ServerPermissionSet, String) Grant(ServerPermissionSet, String) Grant(ServerPermissionSet, String)

Grants the specified set of permissions to the specified grantee on the instance of SQL Server.

public:
 void Grant(Microsoft::SqlServer::Management::Smo::ServerPermissionSet ^ permission, System::String ^ granteeName);
public void Grant (Microsoft.SqlServer.Management.Smo.ServerPermissionSet permission, string granteeName);
Public Sub Grant (permission As ServerPermissionSet, granteeName As String)
Parameters
permission
ServerPermissionSet ServerPermissionSet ServerPermissionSet

A ServerPermissionSet object that specifies the permission.

granteeName
String String String

A String value that specifies the grantee to be granted the specified set of permissions on the instance of SQL Server.

Examples

Visual Basic

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$arg = [Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint  

$sps = new-object Microsoft.SqlServer.Management.Smo.ServerPermissionSet([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  
$sps.Add([Microsoft.SqlServer.Management.Smo.ServerPermission]::AlterAnyEndpoint)  
$spis = $srv.EnumServerPermissions("vGrantee", $sps)  
Write-Host "=================Before revoke==========================="  
Foreach ($spi In $spis)  
{  
   Write-Host $spi.Grantee "has" $spi.PermissionType " permission."  
}  
Write-Host " "  
$sps.Remove([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  

Grant(ServerPermissionSet, String, Boolean) Grant(ServerPermissionSet, String, Boolean) Grant(ServerPermissionSet, String, Boolean)

Grants access to the specified permission to the grantee and the ability to grant access to other users on the instance of SQL Server.

public:
 void Grant(Microsoft::SqlServer::Management::Smo::ServerPermissionSet ^ permission, System::String ^ granteeName, bool grantGrant);
public void Grant (Microsoft.SqlServer.Management.Smo.ServerPermissionSet permission, string granteeName, bool grantGrant);
Public Sub Grant (permission As ServerPermissionSet, granteeName As String, grantGrant As Boolean)
Parameters
permission
ServerPermissionSet ServerPermissionSet ServerPermissionSet

A ServerPermissionSet object that specifies the permission.

granteeName
String String String

A String value that specifies the grantee to be denied specified set of permissions.

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the set of permissions to other users on the instance of SQL Server.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the instance of SQL Server.

If False, the grantee is not given the ability to grant the specified set of permissions to other users on the instance of SQL Server.

Examples

Visual Basic

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$arg = [Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint  

$sps = new-object Microsoft.SqlServer.Management.Smo.ServerPermissionSet([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  
$sps.Add([Microsoft.SqlServer.Management.Smo.ServerPermission]::AlterAnyEndpoint)  
$spis = $srv.EnumServerPermissions("vGrantee", $sps)  
Write-Host "=================Before revoke==========================="  
Foreach ($spi In $spis)  
{  
   Write-Host $spi.Grantee "has" $spi.PermissionType " permission."  
}  
Write-Host " "  
$sps.Remove([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  

Applies to