Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



Tags
#Agile #Docs #Powershell #SQL
Question

CONTEXT: Get-SQLServerPrivileges

How to iterate through the login values ?

Answer
 # 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.


Tags
#Agile #Docs #Powershell #SQL
Question

CONTEXT: Get-SQLServerPrivileges

How to iterate through the login values ?

Answer
?

Tags
#Agile #Docs #Powershell #SQL
Question

CONTEXT: Get-SQLServerPrivileges

How to iterate through the login values ?

Answer
 # 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.

If you want to change selection, open document below and click on "Move attachment"

Documenting SQL Server with PowerShell - Simple Talk
re declared, one to hold the end result and one to iterate through the server roles: 1 2 3 4 5 # Create the result array $result = @() # Create the array for the server roles $serverRoles = @() <span>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. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 # Get all the logins $logins = $server.Logins foreach($login in $logins) { if(($login.Name -notlike "

Summary

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Details

No repetitions


Discussion

Do you want to join discussion? Click here to log in or create user.