Listing logins, users, and database mappings
This recipe lists logins and their corresponding usernames through database mappings.
Getting ready
To check 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-hand pane, as shown in the following screenshot:
How to do it...
To list logins, users, and database mappings, let's use the following steps:
Open PowerShell ISE as an administrator.
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 = "localhost" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
Add the following script and run:
#display login info #these are two different ways of displaying login info...