Sample post-start hook for CDC

This script will add Change Data Capture (CDC) capture and cleanup jobs on provisioned virtual databases.    

$VDB_NAME = $env:VDB_DATABASE_NAME

$VDB_INSTANCE = $env:VDB_INSTANCE_NAME

SQLCMD -b -d $VDB_NAME -r0 -Q "EXEC sys.sp_cdc_add_job @job_type = N'capture';EXEC sys.sp_cdc_add_job @job_type = N'cleanup'" -U <Username> -P <Password> -S ".\$VDB_INSTANCE"

exit $LastExitCode


Sample post-start hook for CDC if provisioning is done from a lower database version to SQL2016 or above

This script will add CDC capture, cleanup jobs, and upgrade CDC metadata on provisioned virtual databases.

$VDB_NAME = $env:VDB_DATABASE_NAME

$VDB_INSTANCE = $env:VDB_INSTANCE_NAME

SQLCMD -b -d $VDB_NAME -r0 -Q "EXEC sys.sp_cdc_add_job @job_type = N'capture';EXEC sys.sp_cdc_add_job @job_type = N'cleanup';EXEC sys.sp_cdc_vupgrade;" -U <Username> -P <Password> -S ".\$VDB_INSTANCE"

exit $LastExitCode
Place real username and password at respective placeholders while using the scripts.