Skip to content

February 18, 2013

Get Login info using Get-SqlConnection

by Scott Newman

Quick post for someone on twitter on how to get login information using sqlpsxs’ Get-SqlConnection.  It appears that all you need is a sql login with public server role in order to list the logins on the server.  The only role that this login was in was the public role on the server.  Nothing else.

In order to get the Get-SqlLogins’ –sqlserver I passed in the ServerInstance from the Get-SqlConnection.  You could probably pipe this as Get-SqlLogin –sqlserver $(Get-SqlConnection –…) as well.

Import-Module SqlServer

$slqcn = Get-SqlConnection -sqlserver "YourServerName" -username "LoginName" -password "P@$$w0r9_123"
Get-SqlLogin -sqlserver $slqcn.ServerInstance | SELECT Name, LoginType, Language, IsSystemObject, CreateDate, DefaultDatabase | Format-Table -AutoSize
Read more from Powershell, SQL Server

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: