Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from
Feb 6, 2019
11 changes: 11 additions & 0 deletions functions/Get-DbaDbRoleMember.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ 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"
try {
uncletimmy3 marked this conversation as resolved.
Show resolved Hide resolved
if ($server.Databases[$item].IsAccessible -eq $false) {
throw "Database: $item is not accessible. Check your permissions or database state."
}
} catch {
Stop-Function -Message 'Failure' -Category ResourceUnavailable -ErrorRecord $_ -Target $instance -Continue
}
}

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

if (Test-Bound -Parameter 'Database') {
Expand Down