Quick script to find which database a table resides in with powershell. This assumes you have a file named servers.txt that lists the servers that you’ll be searching. This uses SQLPSX as well. Easy as cake.
Import-Module SqlServer
$tableName = 'TableName'
$servers = Get-Content c:\Test\Servers.txt
$servers | %{
$srv = $_
Get-SqlDatabase -sqlserver $(Get-SqlServer -sqlserver $_ -username 'UserName' -password '') | where{-not $_.IsSystemObject} | %{
$db = $_
Get-SqlTable -Database $_ | where{$_.Name -eq $tableName} | %{
write-host "$($srv) $($db.Name)"
}
}
}
Leave a comment