Hi,
I'm writing a script that will grab info from a database, then use it to ping servers, then write some results back to the same database. Unfortunately it is falling over when writing back to the database.
Here it is.
Invoke-Sqlcmd
-ServerInstance DPROVDB -Query "select org_id
from organisation_tbl
where opt_id = 3
and org_categories like 'S%'
and org_categories not like '%A%'
and org_categories not like '%M%'
order by org_id desc" | ForEach-Object {
$DENI = $_.org_id
gwmi Win32_PingStatus -Filter "Address='$DENI-am01'" | select IPV4Address | where { $_.IPV4Address -notlike '10.*' } | ForEach-Object {
Invoke-Sqlcmd -ServerInstance DPROVDB -Query "INSERT INTO HoldingDB.dbo.OFFLINESIMS_TMP VALUES ('$DENI')"
}
}
---------------------------------------
I can write-host the results no worries, but when I attempt to run the SQL Insert I recieve this error :
The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods, and only from that same thread. Validate that the cmdlet makes these calls correctly, or please contact Microsoft Support Services.
At :line:1 char:13
+ Invoke-Sqlcmd <<<< -ServerInstance DPROVDB -Query "
----------------------------------------
I've googled the error and I couldn't find anything that related to what I am trying to do. So wondered if anyone could help in any way.
Thanks in advance
Robbie.