hi all - I'm a Newer DBA and my boss has assigned me to look on all our servers (126 of them) and find all the linked servers that are pointing to an oracle database. Of course, I thought of powershell... Ideally, I would like to iterate through a text file with all my server names and put in a text file that has the LinkedServer.Displayname, Datasource and ProductName. Currently I have this:
#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\GLDBA03102\DEFAULT\LinkedServers)) {
$linkedServer.DisplayName, $linkedServer.Datasource, $linkedServer.ProductName | Out-File ("C:\LinkedServers.txt")
}
This does create a text file on my C:\ Drive but it only lists the information on the first linked server it hits (This server has 4 for example) Any idea why it stops at one linked server?
Text file output:
VMSQLSCHED
VMSQLSCHED
SQL Server
In a perfect world, I could do one line for each linked server like:
VMSQLSCHED, VMSQLSCHED, SQL Server