Return SQL Query as Array in Powershell
Posted
by
Emo
on Stack Overflow
See other posts from Stack Overflow
or by Emo
Published on 2010-10-26T21:53:27Z
Indexed on
2014/08/19
4:21 UTC
Read the original article
Hit count: 453
I have a SQL 2008 Ent server with the databases "DBOne", "DBTwo", "DBThree" on the server DEVSQLSRV.
Here is my Powershell script:
$DBNameList = (Invoke-SQLCmd -query "select Name from sysdatabases" -Server DEVSQLSRV)
This produces my desired list of database names as:
Name
-----
DBOne
DBTwo
DBThree
I has been my assumption that anything that is returned as a list is an Array in Powershell. However, when I then try this in Powershell:
$DBNameList -contains 'DBTwo'
It comes back has "False" instead of "True" which is leading me to believe that my list is not an actual array.
Any idea what I'm missing here?
Thanks so much!
Emo
© Stack Overflow or respective owner