Search found 9 matches

by gsaunders
Wed Aug 19, 2020 7:41 pm
Forum: PowerShell GUIs
Topic: Capturing error from invoke-sqlcmd
Replies: 17
Views: 1286

Re: Capturing error from invoke-sqlcmd

SQL that modifies a database does not return a result. If you want output then you have to generate it from your SQL script. So the invoke-sqlcmd that creates the table works fine. And another one that executes a system command works fine. The one that does a simple update doesn't provide anything....
by gsaunders
Wed Aug 19, 2020 1:28 pm
Forum: PowerShell GUIs
Topic: Capturing error from invoke-sqlcmd
Replies: 17
Views: 1286

Re: Capturing error from invoke-sqlcmd

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 bac...
by gsaunders
Wed Aug 19, 2020 12:23 pm
Forum: PowerShell GUIs
Topic: Capturing error from invoke-sqlcmd
Replies: 17
Views: 1286

Re: Capturing error from invoke-sqlcmd

Yea... I get learning it all is impossible.

Definitely making use of the get-help the | gm and other tricks that give you a lot of info.

I definitely need to learn more about other core areas like how data is streamed and so forth.

Thanks again... will check out the book.
by gsaunders
Wed Aug 19, 2020 12:02 pm
Forum: PowerShell GUIs
Topic: Capturing error from invoke-sqlcmd
Replies: 17
Views: 1286

Re: Capturing error from invoke-sqlcmd

"Correct" depends on what you are trying to do. I think I am good now. Basically wanted to capture the information messages you normally would see in the messages windows of SQL. Many of the non-SQL cmdlets worked just fine with $results = get-somecommand where the $results show exactly what the co...
by gsaunders
Wed Aug 19, 2020 11:36 am
Forum: PowerShell GUIs
Topic: Capturing error from invoke-sqlcmd
Replies: 17
Views: 1286

Re: Capturing error from invoke-sqlcmd

Don't use Out-Null. All output of a command will end up in "$results" and it will be an array of lines that can be added to a textbox. Test this at a prompt and not in PSS. When you get the results you want then it can be displayed in the Form. Until you can understand how to use the redirector and...
by gsaunders
Wed Aug 19, 2020 11:21 am
Forum: PowerShell GUIs
Topic: Capturing error from invoke-sqlcmd
Replies: 17
Views: 1286

Re: Capturing error from invoke-sqlcmd

Actually I forgot to put back in the correct where clause that does go through multiple databases. Sorry about that. Should have looked like: Get-SqlDatabase -ServerInstance $ServerName | Where { ($_.Name -ne 'TempDB') } | foreach { Backup-SqlDatabase -DatabaseObject $_ -NoRewind -BackupFile "C:\Tes...
by gsaunders
Wed Aug 19, 2020 9:18 am
Forum: PowerShell GUIs
Topic: Capturing error from invoke-sqlcmd
Replies: 17
Views: 1286

Re: Capturing error from invoke-sqlcmd

So I have found at least one solution, but wonder if this is the best way and if there is another method. But here is what worked with the restore: $Results = (Restore-SqlDatabase -ServerInstance $SQLServer -Database $Database -BackupFile "DBBackup.bak" -ReplaceDatabase -verbose | out-null) 4>&1 Thi...
by gsaunders
Wed Aug 19, 2020 6:22 am
Forum: PowerShell GUIs
Topic: Capturing error from invoke-sqlcmd
Replies: 17
Views: 1286

Re: Capturing error from invoke-sqlcmd

Sorry for delayed response. Let me give a specific example of something I am currently looking at. It is not the invoke-sqlcmd in this example, but the Restore-sqldatabase. So here is the command: Restore-SqlDatabase -ServerInstance $SQLServer -Database $Database -BackupFile "DBBackup.bak" -ReplaceD...
by gsaunders
Wed Aug 12, 2020 8:31 am
Forum: PowerShell GUIs
Topic: Capturing error from invoke-sqlcmd
Replies: 17
Views: 1286

Capturing error from invoke-sqlcmd

Product, version and build: Powershell 2020, 5.7.179 32 or 64 bit version of product: 64bit Operating system: Windows 10 32 or 64 bit OS: 64bit I am doing an Invoke-Sqlcmd from the SQLServer module. This is being called from a button on a form. In the Output of the Studio I see the error I am causin...