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
$AS.connect("server1")

Now if i use the FindByName() property

$db = $AS.Databases.FindByName("database1")
$db.DataSources[0].ConnectionString

I get back the connection string successfully

however if i use Enumerator

foreach ($db in $AS.Databases.GetEnumerator())
{ $dbName = $db.Name
  $dbName
  $dbName.DataSources[0].ConnectionString
}

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

database1

Cannot index into a null array.

database2

Cannot index into a null array.


I tried the following also:

$database1 = "database1"
$database1.DataSources[0].ConnectionString

and i also get back the same exception

So why is it that only FindByName works?

for additional info, this is what GetEnumerator lists:

$AS.Databases.GetEnumerator()

enumerator output

but also $AS.Databases

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

gm -i $AS.Databases

gmdb

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

gmenu

Thanks to James,

https://social.technet.microsoft.com/Forums/en-US/600086bb-89ac-4dac-968d-58b16eca6941/why-is-enumeration-name-property-not-working?forum=winserverpowershell

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}
}