0

I am using the CodePlex project SQL Server PowerShell Extensions (SQLPSX) to generate script files for replication. Everything is working as I want except for one thing. I have looked through the PowerShell code to see if I could suppress this and could not find it. I have tried to create secondary process to remove this item, but my PowerShell skills are not that great.

The output has this line that I do not want.

    exec [DatabaseName].sys.sp_addqreader_agent @job_login = null, @job_password = null, @frompublisher = 1
    GO

We do not use qreader and I don't want this in my output files.

My question is two fold. 1.) Does anyone know how I can modify the SQLPSX code to not write this output. (Preferred) 2.) Add to PowerShell script below to loop through all output files created and remove the two lines listed above.

PowerShell script I found that loops through and generates output files.

param ($sqlServer,$path,[switch]$scriptPerPublication)
Import-Module Repl

if ($sqlServer -eq "")
{
$sqlserver = Read-Host -Prompt "Please provide a value for -sqlServer"
}

if ($path -eq "")
{
$path = Read-Host -Prompt "Please provide a value for output directory path"
}

$scriptOptions = New-ReplScriptOptions
$scriptOptions.IncludeArticles = $true
$scriptOptions.IncludePublisherSideSubscriptions = $true
$scriptOptions.IncludeCreateSnapshotAgent = $true
$scriptOptions.IncludeGo = $true
$scriptOptions.EnableReplicationDB = $true
$scriptOptions.IncludePublicationAccesses = $true
$scriptOptions.IncludeCreateLogreaderAgent = $true
$scriptOptions.IncludeCreateQueuereaderAgent = $true
$scriptOptions.IncludeSubscriberSideSubscriptions = $true

$distributor = Get-ReplServer $sqlserver

if($distributor.DistributionServer -eq $distributor.SqlServerName)
{
$distributor.DistributionPublishers | ForEach-Object {
    $distributionPublisher = $_
    if($distributionPublisher.PublisherType -eq "MSSQLSERVER")
    {
        $outPath =  "{0}\from_{1}\{2}\"  -f    $path,$distributionPublisher.Name.Replace("\","_"),$((Get-Date).toString('yyyy-MMM-dd_HHmmss'))
        New-Item $outPath -ItemType Directory | Out-Null
        Get-ReplPublication $distributionPublisher.Name | ForEach-Object {
            $publication = $_
            $fileName = "{0}{1}.sql" -f $outPath,$publication.DatabaseName.Replace(" ", "")
            if($scriptPerPublication)
            {
                $fileName = "{0}{1}_{2}.sql" -f $outPath,$publication.DatabaseName.Replace(" ", ""),$publication.Name.Replace(" ", "")
            }
            Write-Debug $("Scripting {0} to {1}" -f $publication.Name.Replace(" ", ""),$fileName)
            Get-ReplScript -rmo $publication -scriptOpts $($scriptOptions.ScriptOptions) | Out-File $fileName
        }
    }
}
}
else
{
$outPath =  "{0}\from_{1}\{2}\"  -f     $path,$distributor.SqlServerName.Replace("\","_"),$((Get-Date).toString('yyyy-MMM-dd_HHmmss'))
New-Item $outpath -ItemType Directory | Out-Null
Get-ReplPublication $distributor.SqlServerName | ForEach-Object {
    $publication = $_
    $fileName = "{0}{1}.sql" -f $outPath,$publication.DatabaseName.Replace(" ",  "")
    if($scriptPerPublication)
    {
        $fileName = "{0}{1}_{2}.sql" -f  $outPath,$publication.DatabaseName.Replace(" ", ""),$publication.Name.Replace(" ", "")
    }
    Write-Debug $("Scripting {0} to {1}" -f $publication.Name.Replace(" ", ""),$fileName)
    Get-ReplScript -rmo $publication -scriptOpts $($scriptOptions.ScriptOptions) | Out-File $fileName
}
}

1 Answer 1

1

In the $scriptingoptions collection, you are explicitly setting on the Queue reader agent export. Change this line:

$scriptOptions.IncludeCreateQueuereaderAgent = $true

to

$scriptOptions.IncludeCreateQueuereaderAgent = $false

If you want help with the module you are using, you need to show the code you are using to generate the scripts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.