PowerShell

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.

This post was last modified on 2 stycznia, 2019 20:37

Przemyslaw Klys

System Architect with over 14 years of experience in the IT field. Skilled, among others, in Active Directory, Microsoft Exchange and Office 365. Profoundly interested in PowerShell. Software geek.

Share
Published by
Przemyslaw Klys

Recent Posts

Upgrade Azure Active Directory Connect fails with unexpected error

Today, I made the decision to upgrade my test environment and update the version of…

2 miesiące ago

Mastering Active Directory Hygiene: Automating Stale Computer Cleanup with CleanupMonster

Have you ever looked at your Active Directory and wondered, "Why do I still have…

3 miesiące ago

Active Directory Replication Summary to your Email or Microsoft Teams

Active Directory replication is a critical process that ensures the consistent and up-to-date state of…

7 miesięcy ago

Syncing Global Address List (GAL) to personal contacts and between Office 365 tenants with PowerShell

Hey there! Today, I wanted to introduce you to one of the small but excellent…

12 miesięcy ago

Active Directory Health Check using Microsoft Entra Connect Health Service

Active Directory (AD) is crucial in managing identities and resources within an organization. Ensuring its…

1 rok ago

Seamless HTML Report Creation: Harness the Power of Markdown with PSWriteHTML PowerShell Module

In today's digital age, the ability to create compelling and informative HTML reports and documents…

1 rok ago