0

I need to modify the User Mapping of a specific MS SQL Server Login using PowerShell. I need the Login to map to a specific database, while also selecting db_owner as a Database role membership. The only piece of code I have so far is code that will connect to MS SQ Server.

$svc_Obj = Get-WmiObject Win32_Service -filter "name='MSSQLSERVER'"

However, I'm not sure how I would be able to modify the Login's User Mapping with this. Could someone show me how to do this with either this code or with something else?

1 Answer 1

1

There are lots of examples all over the web on how to do this. A quick search using you favorite engine, using your posts' heading would give you a decent list on the topic. Even searching directly on this site, would give you a decent list.

For example:

Connect to SQL Server Database from PowerShell

I have looked around online for a while now and found many similar problems but for some reason I can't seem to get this working.

I am just trying to connect to a SQL server database and output the query results to a file - See PowerShell script below. What I am uncertain about is how to integrate the User ID and Password into the connection string.

Connect to SQL Server Database from PowerShell

Powershell - User Mapping SQL Server 2012

I am trying to script User Mapping for different Login accounts. I have scripted the creation of users and individual server roles, but I can't figure out how to set User Mapping with Powershell, I will also need to set the Database Role membership, in Particular, db_backupoperator

Powershell - User Mapping SQL Server 2012

Connect to SQL Server via Windows PowerShell with SQL Server authentication

Problem In previous tips on Windows PowerShell with SQL Server, you've seen how you can use Windows PowerShell and SMO to administer SQL Server databases. Most of the examples have used Windows authentication to connect to SQL Server. How can I connect to SQL Server via Windows PowerShell using mixed mode authentication?

https://www.mssqltips.com/sqlservertip/1947/connect-to-sql-server-via-windows-powershell-with-sql-server-authentication/

SQL Server: Change the Login Password using PowerShell

Here’s a quick Article detailing a PowerShell script that can be used to change the password for a SQL Server Login.

https://social.technet.microsoft.com/wiki/contents/articles/22767.sql-server-change-the-login-password-using-powershell/rss.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

I saw the User Mapping question while I was searching for an answer, but I wasn't sure if there was a newer way of doing this since the post is over 4 years old.

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.