PSSoftware icon indicating copy to clipboard operation
PSSoftware copied to clipboard

Use of built-in PowerShell commands should be renamed or removed

Open wsmelton opened this issue 6 years ago • 4 comments

The module contains Import-Certificate which is a built-in command for Windows PowerShell in Windows 8 and above. So trying to install this module fails with the below error due to this.

It would better to either remove the command from the module or rename it where it will not overwrite the local command.

06-08 21:26:13 C:\WINDOWS\system32> install-module pssoftware
PackageManagement\Install-Package : The following commands are already available on this system:'Import-Certificate'.
This module 'PSSoftware' may override the existing commands. If you still want to install this module 'PSSoftware',
use -AllowClobber parameter.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package],
   Exception
    + FullyQualifiedErrorId : CommandAlreadyAvailable,Validate-ModuleCommandAlreadyAvailable,Microsoft.PowerShell.Pack
   ageManagement.Cmdlets.InstallPackage

wsmelton avatar Jun 09 '18 02:06 wsmelton

hmmmmm. It seems that on Windows 10 Write-Log is also included (unless I've inadvertently installed PSDesiredStateConfiguration without realizing it).

I know for creating a temp file I was cognizant of the fact that some versions of PowerShell include it, and others didn't. I'll have a think about how to handle this, it may be that we don't need this command on newer PowerShell.

corbob avatar Jun 09 '18 19:06 corbob

Dbatools we support 3.0 and higher and have certificate commands. Chrissy wrote those and I'm not sure if she is using built in commands for them or not.

wsmelton avatar Jun 09 '18 22:06 wsmelton

It looks like all of the dbatools functions have a prefix of dba (well most of them do, and the few that don't wouldn't overlap from what I can tell). This might be what to do for our Import-Certificate.

A nice pester test might be to wrap this command up so that they all return False:

get-command -Module PSSoftware | % { write-host "$_ : $((command $_.name -all | ? Source -like 'Microsoft.PowerShell.*' | measure | select -expandproperty count) -gt 0)" }

Although that being said, I'm not entirely sure why I don't have Import-Certificate on my Windows 10 1803 system...

corbob avatar Jun 12 '18 20:06 corbob

I'm on 1803 and it exist on my machine.

wsmelton avatar Jun 13 '18 01:06 wsmelton