List AD Groups Setup on SQL Server

Here’s a quick powershell snippet to display the Windows groups setup as logins on SQL Server.

?View Code POWERSHELL
Import-Module SQLPS -DisableNameChecking -ErrorAction Ignore; 
Import-Module ActiveDirectory -DisableNameChecking -ErrorAction Ignore;
$sql_server = "sql_instance"; 
$srv = New-Object Microsoft.SqlServer.Management.Smo.Server $sql_server; 
$srv.Logins | Where-Object {$_.LoginType -eq "WindowsGroup";};

Output will be similar to below.

Name                                          Login Type    Created
----                                          ----------    -------
NT SERVICE\ClusSvc                            WindowsGroup  13/10/2013 11:17
NT SERVICE\MSSQLSERVER                        WindowsGroup  13/10/2013 12:17
NT SERVICE\SQLSERVERAGENT                     WindowsGroup  13/10/2013 12:17
Domain\Group 1                                WindowsGroup  04/06/2013 12:29
Domain\Group 2                                WindowsGroup  02/04/2013 11:25
Domain\Group 3                                WindowsGroup  02/04/2013 12:22

Leave a Reply