Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Trying to list all databases with powershell

Author  Topic 

msible
Starting Member

1 Post

Posted - 2014-11-06 : 10:29:55
I have a powershell script that takes a list of servers with SQL Server on them and creates a list of the databases on each server. The code works fine, except when it gets to one particular server it returns only the system databases, excluding even a database I created. I am a domain admin and that role is defined at the server level . I'll include the code, but I'm assuming it has to do with a security property or setting within SQL Server. Thanks!

Add-Type -path "C:\Program Files\Microsoft SQL Server\110\SDK\Assemblies\Microsoft.SqlServer.Smo.dll"
$srvlist = @(get-content "c:\ProgramData\SQLServer\computers.txt")
ForEach($server in $srvlist){
$srv = New-Object "Microsoft.SqlServer.Management.SMO.Server" $server

if ($srv.Status -EQ "Offline" )
{
$dbs = $srv.Databases
ForEach ($db in $dbs)
...
   

- Advertisement -