March 21, 2013 at 12:51 am
Hi ,
Anyone help to script the linkedservers on weekly basis by automatically in text or .sql format file
Regards,
Saran
March 21, 2013 at 8:08 am
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.
March 21, 2013 at 10:34 am
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)
}
March 21, 2013 at 8:37 pm
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