Grant‑SqlDscServerPermission - dsccommunity/SqlServerDsc GitHub Wiki
Grants server permissions to a principal on a SQL Server Database Engine instance.
Grant-SqlDscServerPermission -Login <Login> -Permission <SqlServerPermission[]> [-WithGrant] [-Force]
[-WhatIf] [-Confirm] [<CommonParameters>]
Grant-SqlDscServerPermission -ServerRole <ServerRole> -Permission <SqlServerPermission[]> [-WithGrant] [-Force]
[-WhatIf] [-Confirm] [<CommonParameters>]
This command grants server permissions to an existing principal on a SQL Server Database Engine instance. The principal can be specified as either a Login object (from Get-SqlDscLogin) or a ServerRole object (from Get-SqlDscRole).
$serverInstance = Connect-SqlDscDatabaseEngine
$login = $serverInstance | Get-SqlDscLogin -Name 'MyLogin'
Grant-SqlDscServerPermission -Login $login -Permission ConnectSql, ViewServerState
Grants the specified permissions to the login 'MyLogin'.
$serverInstance = Connect-SqlDscDatabaseEngine
$role = $serverInstance | Get-SqlDscRole -Name 'MyRole'
$role | Grant-SqlDscServerPermission -Permission AlterAnyDatabase -WithGrant -Force
Grants the specified permissions with grant option to the role 'MyRole' without prompting for confirmation.
$serverInstance = Connect-SqlDscDatabaseEngine
$serverInstance | Get-SqlDscLogin | Grant-SqlDscServerPermission -Permission ConnectSql
Grants ConnectSql permission to all logins from the pipeline.
Specifies that the permissions should be granted without any confirmation.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Specifies the Login object for which the permissions are granted. This parameter accepts pipeline input.
Type: Login
Parameter Sets: Login
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
Specifies the permissions to be granted. Specify multiple permissions by providing an array of SqlServerPermission enum values.
Type: SqlServerPermission[]
Parameter Sets: (All)
Aliases:
Accepted values: AdministerBulkOperations, AlterAnyAvailabilityGroup, AlterAnyConnection, AlterAnyCredential, AlterAnyDatabase, AlterAnyEndpoint, AlterAnyEventNotification, AlterAnyEventSession, AlterAnyEventSessionAddEvent, AlterAnyEventSessionAddTarget, AlterAnyEventSessionDisable, AlterAnyEventSessionDropEvent, AlterAnyEventSessionDropTarget, AlterAnyEventSessionEnable, AlterAnyEventSessionOption, AlterAnyLinkedServer, AlterAnyLogin, AlterAnyServerAudit, AlterAnyServerRole, AlterResources, AlterServerState, AlterSettings, AlterTrace, AuthenticateServer, ConnectAnyDatabase, ConnectSql, ControlServer, CreateAnyDatabase, CreateAnyEventSession, CreateAvailabilityGroup, CreateDdlEventNotification, CreateEndpoint, CreateLogin, CreateServerRole, CreateTraceEventNotification, DropAnyEventSession, ExternalAccessAssembly, ImpersonateAnyLogin, SelectAllUserSecurables, Shutdown, UnsafeAssembly, ViewAnyCryptographicallySecuredDefinition, ViewAnyDatabase, ViewAnyDefinition, ViewAnyErrorLog, ViewAnyPerformanceDefinition, ViewAnySecurityDefinition, ViewServerPerformanceState, ViewServerSecurityAudit, ViewServerSecurityState, ViewServerState
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Specifies the ServerRole object for which the permissions are granted. This parameter accepts pipeline input.
Type: ServerRole
Parameter Sets: ServerRole
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
Specifies that the principal should also be granted the right to grant other principals the same permission.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
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
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
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
The Login or ServerRole object must come from the same SQL Server instance
where the permissions will be granted.
If specifying -ErrorAction 'SilentlyContinue'
then the command will silently continue if any errors occur.
If specifying
-ErrorAction 'Stop'
the command will throw an error on any failure.