# Executes an IDbCommand and converts the resultset
# to a Powershell object collection
function ExecuteCommand(
$command = { throw 'Command must be supplied' }
){
$rows = @();
$reader = $command.executereader()
while($reader.read()){
$values = new-object object;
for($i = 0; $i -lt $reader.FieldCount; $i++){
$name = $reader.GetName($i);
$value = $reader.GetValue($i);
Add-Member -in $values noteproperty $name $value
}
$rows+= $values;
}
$reader.Close();
$rows
}
Next week: why I was doing this in the first place (much more interesting)
1 comment:
Usefull post, thanks
Post a Comment