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
MIT License
875 stars 110 forks source link

[Bug]: Unable to install #141

Closed xkeshav closed 11 months ago

xkeshav commented 11 months ago

Describe the problem

I tried using the given command

Install-Module PSScriptTools

but it stops with below error

Install-Package: The following commands are already available on this system:'gsi'. This module 'PSScriptTools' may override the existing commands. If you still want to install this module 'PSScriptTools', use -AllowClobber parameter.

how do we fix this as I do not want to override existing commands.

Expectation

No response

Additional Information

Windows detail

OS Name:                   Microsoft Windows 11 Pro
OS Version:                10.0.22000 N/A Build 22000

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.6
PSEdition                      Core
GitCommitId                    7.3.6
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PowerShell version

4.0

Platform

None

Additional Checks

jdhitsolutions commented 11 months ago

This is normal behavior in PowerShell. The install process notifies you that you have an existing command called gsi already installed. This is presumably an alias. In PowerShell, you can run get-command gsi to see what it is referring to. "Overwriting" doesn't mean overwriting files, just that you could have command conflicts in the same session. That said, if you already installed PSScriptTools, you should use Update-Module. The first thing I would recommend is learning what gsi is.

xkeshav commented 11 months ago

installing for very first time,

PS D:\Developer\blog> Get-Command gsi

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        gsi                                                0.3.5      git-aliases

its is source from git-aliases , now how do I remove that one ?

jdhitsolutions commented 11 months ago

Ok. You can still safely install the PSScriptTools module. It will not overwrite or remove any files in the git-aliases module. What this means is if you have a session open with the git-aliases module imported and then import the PSScriptTools module, the gsi alias from PSScriptTools will 'overwrite' the gsi command from git-aliases in that session. This is only an issue when you are trying to use both modules simultaneously.

One solution is that when you import one of the modules, say the PSScriptTools module, tell PowerShell to use a prefix.

Import-Module PSScriptTools -prefix t

Now, every command in the module will have a t at the beginning of the name. Now you'll have the command tgsi from the PSScriptTools module, and your original gsi command from git-aliases is untouched.

The catch is that you must manually import the module with the prefix.

xkeshav commented 11 months ago

Thanks for the solution.