I have a powershell script to enumerate the members of SQL Server role members using powershell. I have this script
<... cut the connection details for brevity,
$SqlInstance is a Microsoft.SqlServer.Management.Smo.Server object ...>
$db = $SqlInstance.Databases[$Database]
foreach ($role in $db.Roles)
{
foreach ($memberlist in $role.EnumMembers)
{
foreach ($member in $memberlist)
{
Write-Host ($member)
}
}
}
I get output like this:
System.Collections.Specialized.StringCollection EnumMembers()
System.Collections.Specialized.StringCollection EnumMembers()
System.Collections.Specialized.StringCollection EnumMembers()
System.Collections.Specialized.StringCollection EnumMembers()
System.Collections.Specialized.StringCollection EnumMembers()
System.Collections.Specialized.StringCollection EnumMembers()
System.Collections.Specialized.StringCollection EnumMembers()
System.Collections.Specialized.StringCollection EnumMembers()
System.Collections.Specialized.StringCollection EnumMembers()
System.Collections.Specialized.StringCollection EnumMembers()
How do I actually see the role members? Confused.
Worked it out I needed
()
on the end ofEnumMembers
, DOH!