OK i still have a problem here. This is driving me crazy, someone please help
me keep my sanity. (!)
I'm able to get the SQL query back from a function you see below as CallSQL
This returns into $webs as System.Data.DataRow, as expected.
I'm also able to use foreach or foreach-object against the servername, shown
here to simply validate I am getting the proper values:
----start----
>> . .\get_libs.ps1
>> $webs=
>> CallSQL HELPER SAMPSON "set nocount on; select servername from viwserverroles where value='Production'"
>> foreach ($web in $webs)
>> {
>> $thisweb=$web.servername
>> $thisweb
>> } RUSTY
HELPER
----end----
Perfect, i thought - I'm good to go! Not so fast....
I discovered whenever I tried to use the $thisweb variable in the foreach
(or foreach-object, i tried both) for any processing it was passing what
appeared to be a null (or something else, this is the problem) row on the
first pass, and would abort processing.
To help debug this I replaced the a write-host as shown with its output here:
----begin----
>> foreach ($web in $webs)
>> {
>> $thisweb=$web.servername
>> write-Host "found servername $thisweb"
>> } found servername
found servername RUSTY
found servername HELPER
----end----
The first return of $thisweb is unexpected to me, i don't know where it's
coming from. There are no NULL returns in SQL against the same query, in fact
this column doesn't allow them. I can't figure out how to workaround this but
it's got me dead in the water.
I've tried putting in an IF statement in the foreach scriptblock to filter
out what might be getting passed in to the first return on $thisweb, like
"`0" and "" but obviously I'm not getting it.
Here's the return from $webs for reference:
----begin----
2
servername
----------
RUSTY
HELPER
----end----
Remaining calm and thankful for all assistance,
JS