0

I am trying to run the below command:

"SQL Version" = (Invoke-Command -ComputerName $Computer -ScriptBlock { Invoke-Sqlcmd -Query "SELECT SERVERPROPERTY ('edition')"})

The Output just shows:

SQL Version                  : System.Data.DataRow

How do I get it to show the actual results?

onefiscus
  • 129
  • 1
  • 3
  • 15

1 Answers1

0

Your getting back the whole row of data, you need to select it with the .Item property, if you still do it all in one line it would look like below(assuming that 'edition' is the heading for the column you are accessing.

"SQL Version" = (Invoke-Command -ComputerName $Computer -ScriptBlock { Invoke-Sqlcmd -Query "SELECT SERVERPROPERTY ('edition')"}).Item['edition']

Although on an unrelated note please don't use spaces in variable names, makes everything so much less clear and wrapping variable names in quotes is a weird syntax.

Mike Garuccio
  • 2,588
  • 1
  • 11
  • 20
  • I hate spaces as well, but the output is crucial for parsing not done by myself. I am getting this now: Cannot index into a null array. – onefiscus Dec 01 '16 at 16:23
  • I got another function to work "SQL Version" = (Invoke-Command -ScriptBlock {Get-SQLSvrVer $Computer}) but it outputs: SQL Version : @{Edition=Express Edition} – onefiscus Dec 01 '16 at 16:35
  • I got it: "SQL Version" = (Invoke-Command -ScriptBlock {Get-SQLSvrVer $Computer} | foreach { $_.Edition }) – onefiscus Dec 01 '16 at 17:00