Export-MSSQLServerObjects: Working on it...
This commit is contained in:
@@ -38,6 +38,13 @@ ServerName = SDD-VMP04-SQL17\DD_DEVELOP01
|
||||
####################################################################################################
|
||||
DatabaseName = DD_ECM
|
||||
|
||||
####################################################################################################
|
||||
# Set the filter for which objects should be exported. Default is "*", for all objects. #
|
||||
# Example: * #
|
||||
# Example: DEX_ #
|
||||
####################################################################################################
|
||||
ObjectFilter = *
|
||||
|
||||
####################################################################################################
|
||||
# Set if schema names should be written to the export files, like [dbo].[<ObjectName>]. #
|
||||
# Example: true #
|
||||
|
||||
@@ -58,11 +58,6 @@ Set-Variable -Scope Global -Name ModuleDefaultSourcePath -Value "P:\Sk
|
||||
Set-Variable -Scope Global -Name ModuleHKLMRegistryPath -Value "HKLM:\SOFTWARE\Digital Data\Modules"
|
||||
Set-Variable -Scope Global -Name ModuleHKCURegistryPath -Value "HKCU:\SOFTWARE\Digital Data\Modules"
|
||||
|
||||
#Set-Variable -Scope Global -Name UninstallServiceProfile -Value $NULL
|
||||
#Set-Variable -Scope Global -Name InstallServiceProfile -Value $NULL
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
############################################ set functions ############################################
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
@@ -692,7 +687,7 @@ function Export-Objects($objects, $subfolder, $ExportWithDBSchemaName) {
|
||||
if (-not (Test-Path $folder)) { New-Item -ItemType Directory -Path $folder | Out-Null }
|
||||
|
||||
foreach ($object in $objects) {
|
||||
if (-not $object.IsSystemObject) {
|
||||
if ((-not $object.IsSystemObject) -and ($object -match $ObjectFilter.Replace('*','.'))) {
|
||||
|
||||
IF ($ExportWithDBSchemaName) {
|
||||
$fileName = "$($object.Schema).$($object.Name).sql"
|
||||
@@ -714,7 +709,7 @@ function Export-Tables($db, $subfolder, $ExportWithDBSchemaName) {
|
||||
if (-not (Test-Path $folder)) { New-Item -ItemType Directory -Path $folder | Out-Null }
|
||||
|
||||
foreach ($table in $db.Tables) {
|
||||
if (-not $table.IsSystemObject) {
|
||||
if ((-not $table.IsSystemObject) -and ($table -match $ObjectFilter.Replace('*','.'))) {
|
||||
|
||||
IF ($ExportWithDBSchemaName) {
|
||||
$fileName = "$($table.Schema).$($table.Name).sql"
|
||||
@@ -744,13 +739,13 @@ function Export-DatabaseTriggers($db, $subfolder, $ExportWithDBSchemaName) {
|
||||
$folder = Join-Path $outputFolder "$subfolder\Database"
|
||||
if (-not (Test-Path $folder)) { New-Item -ItemType Directory -Path $folder | Out-Null }
|
||||
|
||||
foreach ($trig in $db.Triggers) {
|
||||
if (-not $trig.IsSystemObject) {
|
||||
$fileName = "DBTrigger.$($trig.Name).sql"
|
||||
foreach ($trigger in $db.Triggers) {
|
||||
if ((-not $trigger.IsSystemObject) -and ($table -match $ObjectFilter.Replace('*','.'))) {
|
||||
$fileName = "DBTrigger.$($trigger.Name).sql"
|
||||
$fileName = Get-SafeFileName -InputString $fileName
|
||||
$filePath = Join-Path $folder $fileName
|
||||
$scripter.Options.FileName = $filePath
|
||||
$scripter.Script($trig)
|
||||
$scripter.Script($trigger)
|
||||
Write-Logfile -LogLine "Exporting DB-Trigger: $filePath"
|
||||
}
|
||||
}
|
||||
@@ -762,7 +757,7 @@ function Export-TableTriggers($db, $subfolder, $ExportWithDBSchemaName) {
|
||||
if (-not (Test-Path $folder)) { New-Item -ItemType Directory -Path $folder | Out-Null }
|
||||
|
||||
foreach ($table in $db.Tables) {
|
||||
if (-not $table.IsSystemObject) {
|
||||
if ((-not $table.IsSystemObject) -and ($table -match $ObjectFilter.Replace('*','.'))) {
|
||||
foreach ($trig in $table.Triggers) {
|
||||
$folder = Join-Path $outputFolder "$subfolder\Table\$table"
|
||||
if (-not (Test-Path $folder)) { New-Item -ItemType Directory -Path $folder -ErrorAction SilentlyContinue | Out-Null }
|
||||
@@ -836,6 +831,7 @@ FOREACH ($Module in $Modules) {
|
||||
|
||||
[STRING]$ServerName = $ConfigFileContent."ServerName_$($ConfigFileContent.ServerName[0])"
|
||||
[STRING]$DatabaseName = $ConfigFileContent."DatabaseName_$($ConfigFileContent.DatabaseName[0])"
|
||||
[STRING]$ObjectFilter = $ConfigFileContent."ObjectFilter_$($ConfigFileContent.ObjectFilter[0])"
|
||||
|
||||
[BOOL]$ExportWithDBSchemaName = [System.Convert]::ToBoolean(($ConfigFileContent."ExportWithDBSchemaName_1")[0])
|
||||
[BOOL]$ExportStoredProcedures = [System.Convert]::ToBoolean(($ConfigFileContent."ExportStoredProcedures_1")[0])
|
||||
@@ -957,6 +953,7 @@ Remove-Variable -Name ModuleHKCURegistryPath -Force -ErrorAction Sile
|
||||
|
||||
Remove-Variable -Name serverName -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name databaseName -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name ObjectFilter -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name outputFolder -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name ExportWithDBSchemaName -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name ExportStoredProcedures -Force -ErrorAction SilentlyContinue
|
||||
|
||||
Reference in New Issue
Block a user