PSScriptTools icon indicating copy to clipboard operation
PSScriptTools copied to clipboard

Get-ModuleCommand should (optionally?) look at Value in ExportedCommands

Open cdhunt opened this issue 4 years ago • 6 comments

Is your feature request related to a problem? Please describe. I have a module that uses a DefaultCommandPrefix to disambiguate from built-in cmdlet names. Get-ModuleCommand operates on the key which is the command name before applying the prefix. This causes it to query info on the built-in command versus my command.

Example:

DefaultCommandPrefix = 'my' New-Service vs New-myService

I want info on New-myService

Describe the solution you'd like If Key -ne Value, use Value in Get-ModuleCommand.ps1#L53

Describe alternatives you've considered I don't see anywhere that DefaultCommandPrefix is exposed to the runtime so you can programmatically check.

I believe you could also always just use Value instead of Key.

Additional context

Get-Module myModule| Select-Object -ExpandProperty ExportedCommands


Key                      Value
---                      -----
Get-Client               Get-myClient
Get-Config               Get-myConfig
Get-CurrentContext       Get-myCurrentContext
Get-Namespace            Get-myNamespace
Get-Service              Get-myService
New-Namespace            New-myNamespace
New-Service              New-myService
New-ServicePort          New-myServicePort
New-ServiceSpec          New-myServiceSpec
Remove-Namespace         Remove-myNamespace
Remove-Service           Remove-myService
Set-Namespace            Set-myNamespace
Set-Service              Set-myService
Get-ModuleCommand

   ModuleName: myModule

Name                     Alias      Synopsis
----                     -----      --------
Get-Service              gsv        Gets the services on the computer.
New-Service                         Creates a new Windows service.
Remove-Service                      Removes a Windows service.
Set-Service                         Starts, stops, and suspends a service, and changes its properties.

cdhunt avatar Jul 08 '21 13:07 cdhunt

After poking around ExportedCommands for a few minutes I can't track down what is generating the name with prefix. The prefix or prefixed name doesn't seem to be in CmdletInfo. Pesky FormatData.

cdhunt avatar Jul 08 '21 14:07 cdhunt

What version of PowerShell are you running this under? I modified a module to use a default prefix and this works in 5.1.

image

It also works in PS 7 if the module is loaded

image

But there is a problem if it isn't loaded.

image

But only in PowerShell 7. Windows PowerShell works fine.

jdhitsolutions avatar Jul 08 '21 15:07 jdhitsolutions

Yeah, I'm running in 7.

cdhunt avatar Jul 08 '21 15:07 cdhunt

This looks like a PowerShell 7 bug with Get-Module. Investigating.

jdhitsolutions avatar Jul 08 '21 15:07 jdhitsolutions

Microsoft agrees that this is a bug in PowerShell 7. The workaround for us appears to be first import the module then run Get-ModuleCommand.

jdhitsolutions avatar Jul 08 '21 18:07 jdhitsolutions

This is still a bug in PowerShell 7.2.

jdhitsolutions avatar Nov 30 '21 15:11 jdhitsolutions

Is this still an issue for you? It has been a while since this was opened.

jdhitsolutions avatar Mar 06 '23 15:03 jdhitsolutions

I'm not currently using this module. I can't say.

cdhunt avatar Mar 06 '23 15:03 cdhunt

I think I'm going to close the issue then. We can always re-open it or start anew.

jdhitsolutions avatar Mar 06 '23 15:03 jdhitsolutions