dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

`Invoke-DbaQuery` Doesn't Respect `-Verbose:$false` Syntax

Open mattcargile opened this issue 3 years ago • 3 comments

Verified issue does not already exist?

Yes

What error did you receive?

Error wasn't received. Verbose output is printed using both -Verbose:$false and -Verbose:$true syntax. I wouldn't expect Verbose output to be printed using -Verbose:$false syntax.

Steps to Reproduce

invoke-dbaQuery -sqlinstance '(localdb)\Projectsv15' -Query 'select 1; print ''hello world''' -verbose:$false
invoke-dbaQuery -sqlinstance '(localdb)\Projectsv15' -Query 'select 1; print ''hello world''' -verbose:$true

Are you running the latest release?

Yes

Other details or mentions

I found the issue because of the code below in Install-DbaFirstResponderKit. This usage causes "missing object" Verbose messages to print. My main issue is removing these Verbose messages. So we could either tackle it from usage in either command ( or any other function using that syntax ).

https://github.com/dataplat/dbatools/blob/d7a543866ec305a877e2665e907b533006557d28/functions/Install-DbaFirstResponderKit.ps1#L209

You can see the preferred behavior using the below code.

Test-NetConnection localhost -Verbose:$true
Test-NetConnection localhost -Verbose:$false

What PowerShell host was used when producing this error

PowerShell Core (pwsh.exe), Windows PowerShell (powershell.exe)

PowerShell Host Version

[32;1mName                           Value[0m
[32;1m----                           -----[0m
PSVersion                      7.2.2
PSEdition                      Core
GitCommitId                    7.2.2
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Name                           Value                                                                                                                                      
----                           -----                                                                                                                                      
PSVersion                      5.1.19041.1320                                                                                                                             
PSEdition                      Desktop                                                                                                                                    
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                    
BuildVersion                   10.0.19041.1320                                                                                                                            
CLRVersion                     4.0.30319.42000                                                                                                                            
WSManStackVersion              3.0                                                                                                                                        
PSRemotingProtocolVersion      2.3                                                                                                                                        
SerializationVersion           1.1.0.1                                                                                                                                    

SQL Server Edition and Build number

Microsoft SQL Server 2017 (RTM-CU20) (KB4541283) - 14.0.3294.2 (X64) 
	Mar 13 2020 14:53:45 
	Copyright (C) 2017 Microsoft Corporation
	Standard Edition (64-bit) on Windows Server 2012 R2 Standard 6.3 <X64> (Build 9600: ) (Hypervisor)

.NET Framework Version

PowerShell 7.2.2

.NET 6.0.3

Powershell 5.1

.NET Framework 4.8.4470.0

mattcargile avatar Apr 01 '22 03:04 mattcargile

To remove the missing object messages, use the parameter -OnlyScript with the suitable "Install-*" script for your servers. That's what I do (and that's why I introduced this parameter).

andreasjordan avatar Apr 01 '22 05:04 andreasjordan

Hmm. I do want all of them. Do you figure out the best order when you make your Install function call like when you pass them in?

I'd have to go through all the scripts to see which one should be installed first to prevent the warnings which would be kind of tedious. It appears without the -OnlyScript parameters the files install based on whatever the default directory order is from Get-ChildItem which I assume is alphabetized by Name.

mattcargile avatar Apr 01 '22 06:04 mattcargile

Hi @niphlod - can you have a look at this? I think you are the expert for Invoke-DbaQuery.

andreasjordan avatar May 01 '22 08:05 andreasjordan

Sorry it took so long - but now I have analyzed the problem and have a fix - see linked pr.

andreasjordan avatar Oct 24 '22 10:10 andreasjordan

Thanks, this will be resleased with dbatools 2.0

potatoqualitee avatar Oct 26 '22 06:10 potatoqualitee