jvierra wrote: ↑Wed Aug 19, 2020 12:06 pm
No one ever learns ALL of PS. That is both unnecessary and likely impossible.
PS gets to be great fun the more you learn. Be sure to read the book linked under the "Training" menu above. It is free.
Have fun.
LOL... just when I think I am getting the hang of it.
So now I am NOT getting a result back for a slightly different command:
Code: Select all
$results = Invoke-Sqlcmd -ServerInstance $LAB_SQLServer -Database $TestDB -InputFile '.\ReplaceText.sql' -ErrorVariable sqlerror -OutputSqlErrors $true -ErrorAction stop -Verbose 4>&1
The actual SQL code looks like this:
Code: Select all
alter table aTable disable trigger ALL;
UPDATE aTable SET DocName = REPLACE(DocName,'\\Server1\','\\Server2\')
UPDATE aTable SET DocName = REPLACE(DocName,'\\Server1b\','\\Server2\')
alter table aTable enable trigger ALL;
Just disable trigger, update text with a replace and then enable trigger.
The command runs fine:
Code: Select all
$results = Invoke-Sqlcmd -ServerInstance $SQLServer -Database $Database -InputFile '.\Test.sql' -ErrorVariable sqlerror -OutputSqlErrors $true -ErrorAction stop -Verbose 4>&1
BUT... the $results comes back as a System.Management.Automation.PSCustomObject on the first command listed above where as the other Invoke_SQLCmd referenced second with different sql statement comes back as System.Object holding the results.
The first script is doing the update and the second script that gives results is creating a table.
Why am I not getting $results in the first one and why are the types different?
Thanks