Why is Enumeration Name property not working?

I have a script that i want to display the connection strings of a database

Import-Module SqlServer
$AS = New-Object Microsoft.AnalysisServices.Server

Now if i use the FindByName() property

$db = $AS.Databases.FindByName("database1")

I get back the connection string successfully

however if i use Enumerator

foreach ($db in $AS.Databases.GetEnumerator())
{ $dbName = $db.Name

I get back the database name along with error/exception (because it couldnt get connection string for some reason):


Cannot index into a null array.


Cannot index into a null array.

I tried the following also:

$database1 = "database1"

and i also get back the same exception

So why is it that only FindByName works?

for additional info, this is what GetEnumerator lists:


enumerator output

but also $AS.Databases

outputs the same thing…so whats even the point of the enumerator?

gm -i $AS.Databases


gm -i $AS.Databases..GetEnumerator()


Thanks to James,


PowerShell does its own enumerating.

This done the trick!

foreach ($db in $AS.Databases){
  Write-Hst $db.Name -Fore green
  $db.DataSources | ForEach-Object{$_.ConnectionString}