Historical and Trend Reports in PowerShell

by joharra at 2013-01-04 07:06:53

I was excited to see the draft of this book, since I am also a fan of ditching Excel for database functions.

While trying out some of the code in the document and related modules, I ran across some statements that do not work correctly. I am using PowerShell v2, but I do no think that is the cause of the problem.

In the "Test-Database" function from the "SQLReporting" module, the following line returns an array:
$TypeName = $object | Get-Member | select-object -ExpandProperty TypeName

which causes an error with this line:
$Table = $typename.split(‘.’)[1]
Error: Method invocation failed because [System.Object] doesn’t contain a method named ‘split’.

In order to get it to work properly, I had to change the line to:
$TypeName = ($object | Get-Member | select-object -ExpandProperty TypeName)[0]

or change this one:
$Table = $typename[0].split(‘.’)[1]

Is the behavior different with PowerShell v3?
by DonJ at 2013-01-08 08:19:48
Apparently. It’s working fine as-is in v3 for me. v3 does have automatic object enumeration, which is probably what you’re running into.