Skip to content

Commit

Permalink
Added check if database from $Database array is accessible or not be…
Browse files Browse the repository at this point in the history
…fore getting roles membership (#5046)

* Added check if database from $Database array is accessible or not before getting roles membership

* add messaging in verbose mode

* Invoke-DbatoolsFormatter

* add LoginType to returned [PSCustomObject]$user

* Revert "add LoginType to returned [PSCustomObject]$user"

This reverts commit 9286f97.

revert last commit

* Update Get-DbaDbRoleMember.ps1

got rid of try/catch
add Logintype to output
  • Loading branch information
uncletimmy3 authored and potatoqualitee committed Feb 6, 2019
1 parent 6e63a62 commit ca9ab45
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions functions/Get-DbaDbRoleMember.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ function Get-DbaDbRoleMember {
Stop-Function -Message 'Failure' -Category ConnectionError -ErrorRecord $_ -Target $instance -Continue
}

foreach ($item in $Database) {
Write-Message -Level Verbose -Message "Check if database: $item on $instance is accessible or not"
if ($server.Databases[$item].IsAccessible -eq $false) {
Stop-Function -Message "Database: $item is not accessible. Check your permissions or database state." -Category ResourceUnavailable -ErrorRecord $_ -Target $instance -Continue
}
}

$databases = $server.Databases | Where-Object { $_.IsAccessible -eq $true }

if (Test-Bound -Parameter 'Database') {
Expand Down Expand Up @@ -153,7 +160,7 @@ function Get-DbaDbRoleMember {
Add-Member -Force -InputObject $user -MemberType NoteProperty -Name UserName -Value $user.Name

# Select object because Select-DefaultView causes strange behaviors when assigned to a variable (??)
Select-Object -InputObject $user -Property 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Role', 'UserName', 'Login', 'IsSystemObject'
Select-Object -InputObject $user -Property 'ComputerName', 'InstanceName', 'SqlInstance', 'Database', 'Role', 'UserName', 'Login', 'IsSystemObject', 'LoginType'
}
}
}
Expand All @@ -163,4 +170,4 @@ function Get-DbaDbRoleMember {
end {
Test-DbaDeprecation -DeprecatedOn "1.0.0" -Alias Get-DbaRoleMember
}
}
}

0 comments on commit ca9ab45

Please sign in to comment.