This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing one PowerShell function to find all system admin roles of the SQL Server.
This function helps to those DBAs who are working with PowerShell. Using this function DBAs can easily list out all System Admin roles of a particular database.
Below is a script to create a function:
The DBA has to pass server name as input parameter.
1 2 3 4 5 6 7 8 |
function Find_SystemAdmin_Role ($servername) { $ServerVar="$servername" $ServerVar=New-Object "Microsoft.SqlServer.Management.Smo.Server" "$ServerVar" $ServerRole = $ServerVar.Roles | where {$_.Name -eq 'sysadmin'} $ServerVar $ServerRole.EnumServerRoleMembers() } |
Script to call this function:
1 |
Find_SystemAdmin_Role "ServerName_DBRND" |