Listing logins, users, and database mappings
This recipe lists logins and their corresponding usernames and database mappings.
Getting ready
To check the logins and their database mappings in SQL Server Management Studio, log in to SSMS. Go to the Security
folder, expand Logins
, and double-click on a particular login. This will show you the Login Properties window. Click on the User Mapping option on the left pane, as shown in the following screenshot:
How to do it...
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module and create a new SMO Server object as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your instance name $instanceName = "KERRIGAN" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
Add the following script and run it:
#display login info #these are two different ways of displaying login info $server.Logins...