jdhitsolutions / PSScriptTools

:wrench: :hammer: A set of PowerShell functions you might use to enhance your own functions and scripts or to facilitate working in the console. Most should work in both Windows PowerShell and PowerShell 7, even cross-platform. Any operating system limitations should be handled on a per command basis. The Samples folder contains demonstration script files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

cdhunt opened this issue · 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.

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.

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.

Yeah, I'm running in 7.

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

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.

This is still a bug in PowerShell 7.2.

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

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

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