Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Testing all Linked Servers in all SQL SERVER servers with Powershell

By Laerte Poltronieri Junior,

This scripts "walk" in all servers, previously registered in one txt and search for linked servers in every server and test them.Because testconnection method in SMO does not return values just an error, i use the "trap" to insert the linked server with error.


This script use SQLPS minishell of sql server 2008 and one job step powershell. If want to use powershell shell, it is necessary load the snapins for sql server.


First create a txt with all servers and save in a folder (i use C:\dadosps\servers.txt)..something like that






And save with name servers.txt


Create repository table in a server repository. I call "SERVER1\MSSQLSERVER_1" and database is "DBA"

This table will have the information about the linked servers with error in all servers.


Finally, we can use this script or save in .ps1


How can i say, i use this script since last year when i did it, its works fine and i call it in a sql server 2008 job step with powershell type.



Total article views: 2112 | Views in the last 30 days: 13
Related Articles

Execute SQL Script against Multiple Servers by PowerShell

Execute SQL Script against Multiple Servers by PowerShell


PowerShell - Restart Services

A PowerShell script which restarts any service running on a server.


SQL Powershell Script to check Server Uptime Remotely

SQL Powershell Script to check Server Uptime Remotely


Script Replication with PowerShell

I promised you some PowerShell scripts this year and this post is the first one.  I can see the valu...


Paging Doctor Powershell

Use Powershell to create a single script that checks over your server and every SQL instance on it t...


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones