CONTEXT: Get-SQLServerPrivileges
How to iterate through the login values ?
# Get all the logins
$logins = $server.Logins
foreach($login in $logins)
{
if(($login.Name -notlike "##*"))
{
# Get all the server
$serverRoles = ($login.ListMembers()) -join ","
# Make the result
if($serverRoles.Count -gt 1)
{
$result += $login | Select `
Name,LoginType,CreateDate,DateLastModified,IsDisabled,`
@{N="ServerRoles";E=([string]::Join(",", $serverRoles))} | Sort-Object Name
}
else
{
$result += $login | Select `
Name,LoginType,CreateDate,DateLastModified,IsDisabled,`
@{N="ServerRoles";E={$serverRoles}} | Sort-Object Name
}
# Clear the array
$serverRoles = @()
}
}
return $result
}
To get the SQL Server logins, and associated server roles, we call the Logins property from the server object and save the values to the $logins variable, and then iterate through these login values (excluding system accounts, which start with “##”). If the login is a member of Windows group we create a comma separated list of all the server roles of which that group is a member. Finally, we clear the array of the server roles to be sure the data is correct, and then return the result.
CONTEXT: Get-SQLServerPrivileges
How to iterate through the login values ?
CONTEXT: Get-SQLServerPrivileges
How to iterate through the login values ?
# Get all the logins
$logins = $server.Logins
foreach($login in $logins)
{
if(($login.Name -notlike "##*"))
{
# Get all the server
$serverRoles = ($login.ListMembers()) -join ","
# Make the result
if($serverRoles.Count -gt 1)
{
$result += $login | Select `
Name,LoginType,CreateDate,DateLastModified,IsDisabled,`
@{N="ServerRoles";E=([string]::Join(",", $serverRoles))} | Sort-Object Name
}
else
{
$result += $login | Select `
Name,LoginType,CreateDate,DateLastModified,IsDisabled,`
@{N="ServerRoles";E={$serverRoles}} | Sort-Object Name
}
# Clear the array
$serverRoles = @()
}
}
return $result
}
To get the SQL Server logins, and associated server roles, we call the Logins property from the server object and save the values to the $logins variable, and then iterate through these login values (excluding system accounts, which start with “##”). If the login is a member of Windows group we create a comma separated list of all the server roles of which that group is a member. Finally, we clear the array of the server roles to be sure the data is correct, and then return the result.
status | not learned | measured difficulty | 37% [default] | last interval [days] | |||
---|---|---|---|---|---|---|---|
repetition number in this series | 0 | memorised on | scheduled repetition | ||||
scheduled repetition interval | last repetition or drill |