Skip to content

Added IsCdCEnabled to Get-DbaDatabase #9670

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

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions public/Get-DbaDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,11 @@ function Get-DbaDatabase {
SUSER_SNAME(sid) AS [Owner]
FROM master.dbo.sysdatabases
")
} elseif ($server.VersionMajor -eq 9) {
# CDC did not exist in version 9, but did afterwards.
$server.Query("SELECT name, state, SUSER_SNAME(owner_sid) AS [Owner], 0 AS is_cdc_enabled FROM sys.databases")
} else {
$server.Query("SELECT name, state, SUSER_SNAME(owner_sid) AS [Owner] FROM sys.databases")
$server.Query("SELECT name, state, SUSER_SNAME(owner_sid) AS [Owner], is_cdc_enabled FROM sys.databases")
}
} catch {
Stop-Function -Message "Failure" -ErrorRecord $_
Expand Down Expand Up @@ -376,11 +379,12 @@ function Get-DbaDatabase {
Add-Member -Force -InputObject $db -MemberType NoteProperty -Name SqlInstance -Value $server.DomainInstanceName
Add-Member -Force -InputObject $db -MemberType NoteProperty -Name LastRead -Value $lastusedinfo.last_read
Add-Member -Force -InputObject $db -MemberType NoteProperty -Name LastWrite -Value $lastusedinfo.last_write
Add-Member -Force -InputObject $db -MemberType NoteProperty -Name IsCdcEnabled -Value ($backed_info | Where-Object { $_.name -ceq $db.name }).is_cdc_enabled
Select-DefaultView -InputObject $db -Property $defaults
}
} catch {
Stop-Function -ErrorRecord $_ -Target $instance -Message "Failure. Collection may have been modified. If so, please use parens (Get-DbaDatabase ....) | when working with commands that modify the collection such as Remove-DbaDatabase." -Continue
}
}
}
}
}