views:

210

answers:

1

The following PowerShell code loads a SQL result into a dataset:

$sqlCommand = "SELECT A, B FROM TestTable"
$connection = New-Object System.Data.OleDb.OleDbConnection $connectionString
$command = New-Object System.Data.OleDb.OleDbCommand $sqlCommand,$connection
$connection.Open()
$adapter = New-Object System.Data.OleDb.OleDbDataAdapter $command
$dataset = New-Object System.Data.DataSet
[void] $adapter.Fill($dataSet)

I'm surprised to learn that $dataset.Tables[0].Rows[0].A works! I tried piping the row to Get-Member and indeed A and B are listed as properties of the object. Does anyone know why this is working? The DataSet was not generated from a XSD. I tried writing the same lines of code in C# and using the debugger I cannot see the properties A and B.

+1  A: 

This is part of PowerShell's extended type system. For a number of known types such as Datasets, XML Documents, COM, AD, and WMI objects, PowerShell will wrap the underlying native object in a PSObject which has the additional properties which are so welcome.

Scott Weinstein