Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Anyone help to script the linkedservers on weekly basis by automatically Expand / Collapse
Author
Message
Posted Thursday, March 21, 2013 12:51 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 11:07 PM
Points: 29, Visits: 410
Hi ,


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


Regards,
Saran
Post #1433605
Posted Thursday, March 21, 2013 8:08 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, July 15, 2014 2:31 PM
Points: 151, Visits: 391
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.
Post #1433803
Posted Thursday, March 21, 2013 10:34 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 2:36 PM
Points: 1,431, Visits: 2,705
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
Post #1433903
Posted Thursday, March 21, 2013 8:37 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 11:07 PM
Points: 29, Visits: 410
Receiving an Errror.. Its not working


Post #1434115
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse