dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.44k stars 796 forks source link

dbatools module prevents Show-Command from working #9225

Open corbob opened 8 months ago

corbob commented 8 months ago

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?


PSMessageDetails      : 
Exception             : System.Reflection.TargetInvocationException: Exception has been thrown by the target of an 
                        invocation. ---> System.Management.Automation.RuntimeException: Unable to find type 
                        [Microsoft.SqlServer.Replication.Article].
                           at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName, IScriptExtent 
                        errorPos)
                           at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName, IScriptExtent 
                        errorPos)
                           at System.Management.Automation.Language.Compiler.GetAttribute(TypeConstraintAst 
                        typeConstraintAst)
                           at System.Management.Automation.Language.Compiler.GetRuntimeDefinedParameter(ParameterAst 
                        parameterAst, Boolean& customParameterSet, Boolean& usesCmdletBinding)
                           at System.Management.Automation.Language.Compiler.GetParameterMetaData(ReadOnlyCollection`1 
                        parameters, Boolean automaticPositions, Boolean& usesCmdletBinding)
                           at System.Management.Automation.CompiledScriptBlockData.InitializeMetadata()
                           at System.Management.Automation.CompiledScriptBlockData.get_CmdletBindingAttribute()
                           at System.Management.Automation.CommandMetadata..ctor(ScriptBlock scriptblock, String 
                        commandName, ExecutionContext context)
                           at System.Management.Automation.FunctionInfo.get_CommandMetadata()
                           at System.Management.Automation.CommandInfo.GenerateCommandParameterSetInfo()
                           at System.Management.Automation.CommandInfo.get_ParameterSets()
                           at 
                        Microsoft.PowerShell.Commands.ShowCommandExtension.ShowCommandCommandInfo..ctor(CommandInfo 
                        other)
                           at 
                        Microsoft.PowerShell.Commands.ShowCommandInternal.ShowCommandHelper.GetCommandList(Object[] 
                        commandObjects)
                           --- End of inner exception stack trace ---
                           at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature 
                        sig, Boolean constructor)
                           at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] 
                        parameters, Object[] arguments)
                           at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder 
                        binder, Object[] parameters, CultureInfo culture)
                           at Microsoft.PowerShell.Commands.ShowCommandProxy.GetCommandList(Object[] commandObjects)
                           at Microsoft.PowerShell.Commands.ShowCommandCommand.CanProcessRecordForAllCommands()
                           at Microsoft.PowerShell.Commands.ShowCommandCommand.ProcessRecord()
                           at System.Management.Automation.CommandProcessor.ProcessRecord()
TargetObject          : 
CategoryInfo          : NotSpecified: (:) [Show-Command], TargetInvocationException
FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Microsoft.PowerShell.Commands.ShowCommandCommand
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

Steps to Reproduce

Import-Module dbatools
Show-Command # Results in error
# For completeness, how I proved it was dbatools:
Remove-Module dbatools
Show-Command # No longer results in error.

Please confirm that you are running the most recent version of dbatools

2.1.7

Other details or mentions

After getting the full error details, it occurred to me based on the error that it was likely a command that took in a pipeline object, and something about the object. So to determine the command(s) causing issues I ran: get-command -Module dbatools | % { $cmd = $_.name; try { show-command $cmd } catch { Write-Host $cmd } } and just held down the Escape key to close all the Show-Command windows that appeared. It eventually came back with Remove-DbaReplArticle and Remove-DbaReplPublication. Based on the error variables from those commands it looks like it's the Microsoft.SqlServer.Replication.Publication and Microsoft.SqlServer.Replication.Article types causing issues.

What PowerShell host was used when producing this error

Windows PowerShell (powershell.exe)

PowerShell Host Version

Name                           Value                                                                                   
----                           -----                                                                                   
PSVersion                      5.1.20348.2227                                                                          
PSEdition                      Desktop                                                                                 
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                 
BuildVersion                   10.0.20348.2227                                                                         
CLRVersion                     4.0.30319.42000                                                                         
WSManStackVersion              3.0                                                                                     
PSRemotingProtocolVersion      2.3                                                                                     
SerializationVersion           1.1.0.1                                                                                 

SQL Server Edition and Build number

N/A

.NET Framework Version

PSChildName Version  
----------- -------  
Client      4.8.04161
Full        4.8.04161
Client      4.0.0.0