Skip to content

Instantly share code, notes, and snippets.

@PCfromDCSnippets
Created October 25, 2019 19:57
Show Gist options
  • Save PCfromDCSnippets/2210bbc9ffaa62522db248170f8cd8f8 to your computer and use it in GitHub Desktop.
Save PCfromDCSnippets/2210bbc9ffaa62522db248170f8cd8f8 to your computer and use it in GitHub Desktop.
Create-VmUserRole
/** Run on Master DB **/
/** Change variables to name of VM needing Access to Azure DB **/
DECLARE @vmName1 NVARCHAR(20) = 'AzDO-01'
/** Declare query variables **/
DECLARE @query1 NVARCHAR(MAX),
@query2 NVARCHAR(MAX)
/** Update @vmName1 **/
SET @query1 = CONCAT('CREATE USER [', @vmName1, '] FROM EXTERNAL PROVIDER')
SET @query2 = CONCAT('ALTER ROLE [dbmanager] ADD MEMBER [', @vmName1, ']')
/** Execute query variables **/
EXEC sp_executesql @query1
EXEC sp_executesql @query2
/**
CREATE USER [azdo-app-01] FROM EXTERNAL PROVIDER
ALTER ROLE [dbmanager] ADD MEMBER [azdo-app-01]
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment