Click here to monitor SSC
SQLServerCentral is supported by Redgate
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: 2478 | Views in the last 30 days: 5
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...


Check SQL Error Logs using Powershell

Dynamically check your SQL Error Logs and filter using Powershell.