Getting error while executing PowerShell script

Mar 24, 2008 at 8:30 PM
Hi, I had no problems executing powershell script to get local version, but when executing DMV query script, I am getting following error:

PS C:\Documents and Settings\Vidas> c:\Invoke-DMV.ps1 -Sql "SELECT * FROM $SYSTEM.Discover_Connections" -Server "XP-VM1"

Exception calling "Fill" with "1" argument(s): "Query (1, 15) Parser: The syntax for '.' is incorrect."
At C:\Invoke-DMV.ps1:40 char:21
+ void $adapter.Fill( <<<< $dataSet)
Unable to index into an object of type System.Data.DataTableCollection.
At C:\Invoke-DMV.ps1:44 char:17
+ $dataSet.Tables0 <<<<
PS C:\Documents and Settings\Vidas>

Any suggestions where should I look to solve this?
Mar 26, 2008 at 12:59 AM
Use single quote rather than double-quote as indicated in the example in the file. I will update project soon.

C:\Documents and Settings\Vidas> c:\Invoke-DMV.ps1 -Sql 'SELECT * FROM $SYSTEM.Discover_Connections' -Server 'XP-VM1'

Mar 26, 2008 at 1:37 AM
Single quotes works! Thank you.

By the way, examples at the top of this file use double quotes, that is what confused me.

Thanks again

Vidas Matelis
Mar 26, 2008 at 3:23 PM
I know - sorry for the confusion. Will be fixed.
Oct 20, 2008 at 2:33 AM
You could make this work with single or double quote strings by putting the following like at the top of your script.

$System = '$SYSTEM'

This is because variables are expanded inside double quote strings and the $system is treated as a variable and evaluates to an empty string. So if we create a variable called $System and give it a value of '$SYSTEM' it will work both ways. (which would be nice for people that are not used to PowerShell)