Home Forums Programming Powershell Need a way to script out LinkedServers on a SQL 2005\2008 boxes but place the script in seperate files. RE: Need a way to script out LinkedServers on a SQL 2005\2008 boxes but place the script in seperate files.

  • This worked for me:

    Add-PSSnapin SqlServerCmdletSnapin100 -ErrorAction SilentlyContinue

    Add-PSSnapin SqlServerProviderSnapin100 -ErrorAction SilentlyContinue

    [System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.Smo’) | Out-Null

    foreach($linkedServer in (Get-ChildItem SQLSERVER:\SQL\MYSERVER\DEFAULT\LinkedServers)) {

    $linkedServer.Script() | Out-File ("C:\LinkedServer." + $linkedServer.Name.Replace(".","_").Replace("\","$") + ".sql")

    }

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato