Anyone help to script the linkedservers on weekly basis by automatically

  • Hi ,

    Anyone help to script the linkedservers on weekly basis by automatically in text or .sql format file

    Regards,

    Saran

  • saranya.priyadharshini (3/21/2013)


    Hi ,

    Anyone help to script the linkedservers on weekly basis by automatically in text or .sql format file

    Regards,

    Saran

    You may want to provide more detail I dont really understand what you want to achieve.

  • If you want to script out the linked server definitions, here is a powershell script that will accomplish this.

    Add-PSSnapin SqlServerProviderSnapin100

    Add-PSSnapin SqlServerCmdletSnapin100

    $server="<servername>"

    $scriptpath="<path of script file>"

    cd SQLSERVER:\SQL\$server\DEFAULT\LinkedServers

    $Scripter=new-object ("Microsoft.SqlServer.Management.Smo.Scripter") ($server)

    $Scripter.Options.DriAll=$True

    $Scripter.Options.IncludeHeaders=$True

    $Scripter.Options.ToFileOnly=$True

    $Scripter.Options.WithDependencies=$False

    foreach ($Item in Get-ChildItem) {

    $filename = $Item.ToString()

    $filename = $filename.Replace("\","_")

    $Scripter.Options.FileName=$scriptpath+$filename + ".sql"

    $Scripter.Options.AppendToFile=$False

    $Scripter.Options.ScriptDrops=$True;

    $Scripter.Options.IncludeIfNotExists=$True;

    $Scripter.Script($Item)

    $Scripter.Options.ScriptDrops=$False;

    $Scripter.Options.IncludeIfNotExists=$False;

    $Scripter.Options.AppendToFile=$True

    $Scripter.Script($Item)

    }

    Bob
    -----------------------------------------------------------------------------
    How to post to get the best help[/url]

  • Receiving an Errror.. Its not working

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply