fbpx

Artykuł

A command with name is already available on this system. This module may override the existing commands.

Another day, another issue one may say. Today I wanted to install one of my modules to a new server and was greeted with a well-known message (it may seem on first look):

A command with name ” is already available on this system. This module ‚PSEventViewer’ may override the existing commands. If you still want to install this module ‚PSEventViewer’, use -AllowClobber parameter.

What is important here to notice is that command name was left blank. Usually, the command name would be filled in, and that's something to be expected that there may be some other module using the same name for one of the commands. But this was an almost clean system so it seemed impossible to me that my small module would hit a clash with some other module. I also have seen this error on Azure DevOps during Pester Testing of some of my modules where I've merely overridden the settings with AllowClobber switch because I just thought there's some conflict with something existing on test machines.

Knowing that it has to be my module having a problem I've decided to check two places that made the most sense to me as possible suspects:

PSD1 file, especially Functions = @() and Aliases = @() section.
PSM1 file, in particular, Export-ModuleMember function which delivers information what functions and aliases to export.

And to my expectations I was right, that's where my mistake was. Can you see it yet?

Export-ModuleMember `
    -Function @('Get-Events','Get-EventsFilter','Get-EventsInformation') `
    -Alias @('')

Recently as part of my optimization process to speed up loading of modules I've written a module that has one neat feature of integrating all functions into single PSM1 file (Why? Have a read here). During that process, it also adds Export-ModuleMember at the end of the file. If you've not yet noticed where the error is it seems that Export-ModuleMember -Function @(‚MyFunction’) -Alias @(”) at fault. I've made mistake and left Alias Array with a single member. An empty string. I thought it wouldn't matter but it seems it does.

How did you fix it?

So how do I fix this issue? I simply had to modify my module to create an empty Array @() for Alias parameter instead of Array with an empty string. Simple, but effective, and another reason that small things matter and we have to pay attention to details.

Tags: ,

This is a unique website which will require a more modern browser to work! Please upgrade today!