SqlBackupRestoreTools.psm1
|
# Module entry point # Publish-ready structure (Public/ + Private/) while keeping backwards compatibility. $moduleRoot = Split-Path -Parent $PSCommandPath # In PowerShell Core, SqlServer/Invoke-Sqlcmd can default to encrypted connections and fail # against instances using self-signed/untrusted certificates (common for local dev). # Apply safe defaults for this module only; users can opt out via env var. if ($PSVersionTable.PSEdition -eq 'Core' -and -not $env:SQLBACKUPRESTORETOOLS_DISABLE_TLS_DEFAULTS) { try { # Make Invoke-Sqlcmd available so parameter discovery works. Import-Module SqlServer -ErrorAction SilentlyContinue | Out-Null $invoke = Get-Command Invoke-Sqlcmd -ErrorAction SilentlyContinue if ($invoke) { if ($invoke.Parameters.ContainsKey('TrustServerCertificate')) { if (-not $PSDefaultParameterValues.ContainsKey('Invoke-Sqlcmd:TrustServerCertificate')) { $PSDefaultParameterValues['Invoke-Sqlcmd:TrustServerCertificate'] = $true } } if ($invoke.Parameters.ContainsKey('Encrypt')) { if (-not $PSDefaultParameterValues.ContainsKey('Invoke-Sqlcmd:Encrypt')) { $PSDefaultParameterValues['Invoke-Sqlcmd:Encrypt'] = 'Optional' } } } } catch { # If SqlServer isn't available, other code paths will report a clearer missing dependency. } } $privatePath = Join-Path $moduleRoot 'Private' if (Test-Path $privatePath) { Get-ChildItem -Path $privatePath -Filter '*.ps1' -File | Sort-Object Name | ForEach-Object { . $_.FullName } } $publicPath = Join-Path $moduleRoot 'Public' if (Test-Path $publicPath) { Get-ChildItem -Path $publicPath -Filter '*.ps1' -File | Sort-Object Name | ForEach-Object { . $_.FullName } } # Load per-user persisted configuration (opt-out via env var SQLBACKUPRESTORETOOLS_DISABLE_PERSISTED_CONFIG). if (Get-Command Initialize-SbrtConfigFromDisk -ErrorAction SilentlyContinue) { Initialize-SbrtConfigFromDisk } # Export the stable public surface area. Export-ModuleMember -Function @( 'BackupAndRestore', 'Backup-DbalDatabase', 'Clear-DBALibraryConfig', 'Get-DBALibraryConfig', 'Restore-DbalDatabase', 'Set-DBALibraryConfig' ) |