1

How do we run CREATE LOGIN ... against a variable string?

enter image description here

I'm executing the following command:

Invoke-Sqlcmd -ServerInstance $ServerInstance -Database 'master' -Username $DBAdminAccount -Password $DBAdminPassword -Variable $SqlVariables -InputFile $ArtifactStagingDirectory\MasterDBSetup.sql

MasterDBSetup.sql:

....
    IF NOT EXISTS (SELECT name  FROM sys.sql_logins WHERE name = '$(SvcRRRComparisonUser)')
    BEGIN 
        CREATE LOGIN '$(SvcRRRComparisonUser)' WITH PASSWORD = '$(RRRComparisonUserPassword)'
    END
....

How do we run CREATE LOGIN ... against $(SvcRRRComparisonUser) ?

1 Answer 1

2

In the $SqlVariables:

$SqlVariables = @("SvcRRRComparisonUser='user1',RRRComparisonUserPassword='pass1'")

Then in the SQL file:

IF NOT EXISTS (SELECT name  FROM sys.sql_logins WHERE name = $(SvcRRRComparisonUser)
BEGIN 
    CREATE LOGIN $(SvcRRRComparisonUser) WITH PASSWORD = $(RRRComparisonUserPassword)
END
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.