function Get-SQLServerPrivileges
{
<#
.SYNOPSIS
Returns each server login with their server roles
.DESCRIPTION
This function will return all the logins on the database server
and check whether they are member of a server role.
.PARAMETER instance
This is the instance that needs to be connected
.EXAMPLE
Get-SQLServerPrivileges "SQL01"
.EXAMPLE
Get-SQLServerPrivileges "SQL01\INST01"
.EXAMPLE
Get-SQLServerPrivileges -inst "SQL01\INST01"
.INPUTS
.OUTPUTS
System.Array
.NOTES
.LINK
#>
param
(
[Parameter(Mandatory = $true, Position=1)]
[ValidateNotNullOrEmpty()]
[string]$inst = $null
)
# Check if assembly is loaded
Load-Assembly -name 'Microsoft.SqlServer.SMO'
# Check if the instance object is already initiated
if($server -eq $null)
{
try{
$server = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $inst
}
catch [Exception]
{
Write-Host "$_.Exception.GetType().FullName, $_.Exception.Message" -ForegroundColor Red
}
}
# Create the result array
$result = @()
# Create the array for the server roles
$serverRoles = @()
# Get all the logins
$logins = $server.Logins
# Loop through the 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 += $logn | Select `
Name,LoginType,CreateDate,DateLastModified,IsDisabled,`
@{N="ServerRoles";E={$serverRoles}} | Sort-Object Name
}
# Clear the array
$serverRoles = @()
}
}
return $result
}
[default - edit me]
function Get-SQLServerPrivileges
{
<#
.SYNOPSIS
Returns each server login with their server roles
.DESCRIPTION
This function will return all the logins on the database server
and check whether they are member of a server role.
.PARAMETER instance
This is the instance that needs to be connected
.EXAMPLE
Get-SQLServerPrivileges "SQL01"
.EXAMPLE
Get-SQLServerPrivileges "SQL01\INST01"
.EXAMPLE
Get-SQLServerPrivileges -inst "SQL01\INST01"
.INPUTS
.OUTPUTS
System.Array
.NOTES
.LINK
#>
param
(
[Parameter(Mandatory = $true, Position=1)]
[ValidateNotNullOrEmpty()]
[string]$inst = $null
)
# Check if assembly is loaded
Load-Assembly -name 'Microsoft.SqlServer.SMO'
# Check if the instance object is already initiated
if($server -eq $null)
{
try{
$server = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $inst
}
catch [Exception]
{
Write-Host "$_.Exception.GetType().FullName, $_.Exception.Message" -ForegroundColor Red
}
}
# Create the result array
$result = @()
# Create the array for the server roles
$serverRoles = @()
# Get all the logins
$logins = $server.Logins
# Loop through the 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 += $logn | Select `
Name,LoginType,CreateDate,DateLastModified,IsDisabled,`
@{N="ServerRoles";E={$serverRoles}} | Sort-Object Name
}
# Clear the array
$serverRoles = @()
}
}
return $result
}
[default - edit me]
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 |