PoshCode / ModuleBuilder

A PowerShell Module to help scripters write, version, sign, package, and publish.
MIT License
445 stars 54 forks source link

Error when running Install-RequiredModule.ps1 #111

Closed fabricesemti80 closed 7 months ago

fabricesemti80 commented 2 years ago

Error as follows:


(Elevated) adm.fsemti@MER-PRD-RDS01 : ~\Documents\my-module\ModuleBuilder : 14/12/2021 12:50:40 :  [main ≡]
> .\Install-RequiredModule.ps1
Install-RequiredModule : The term 'Install-RequiredModule' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\adm.fsemti\Documents\my-module\ModuleBuilder\Install-RequiredModule.ps1:4 char:5
+     Install-RequiredModule
+     ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Install-RequiredModule:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

My PS version:

(Elevated) adm.fsemti@MER-PRD-RDS01 : ~\Documents\my-module\ModuleBuilder : 14/12/2021 12:55:51 :  [main ≡]
> $PSVersionTable

Name                           Value                                                                                                                                                                                                                             
----                           -----                                                                                                                                                                                                                             
PSVersion                      5.1.14393.4583                                                                                                                                                                                                                    
PSEdition                      Desktop                                                                                                                                                                                                                           
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                                           
BuildVersion                   10.0.14393.4583                                                                                                                                                                                                                   
CLRVersion                     4.0.30319.42000                                                                                                                                                                                                                   
WSManStackVersion              3.0                                                                                                                                                                                                                               
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                                               
SerializationVersion           1.1.0.1   

Any suggestion would be appreciated!

Jaykul commented 2 years ago

Hmm, that's weird. That script is really just two lines:

    Install-Script Install-RequiredModule
    Install-RequiredModule

The first line seems to have worked... Which should mean the second line can work!

My best guess is that PowerShellGet installed the script into your ~\Documents\WindowsPowerShell\Scripts but didn't make sure that folder was in your PATH environment variable. Try looking in there:

Get-ChildItem (Split-Path $Profile | Join-Path -ChildPath Scripts)

And if you find it, add that folder to your PATH:

$Env:Path += ";" + (Split-Path $Profile | Join-Path -ChildPath Scripts)

And/or, add it permanently:

$Path = [Environment]::GetEnvironmentVariable("PATH", "User") + ";" + (Split-Path $Profile | Join-Path -ChildPath Scripts)
[Environment]::SetEnvironmentVariable("PATH", $Path, "User")
schlich commented 2 years ago

I got stuck on this for quite a while... would be helpful to include a note to hit YES when prompted to add the /Scripts folder to your path... i clicked "no" because i didn't read the prompt completely and got stuck on this for a couple hours... my way out was to just run Install-Script .\Install-RequiredModule.ps1 manually, hit "yes" when prompted to add /Scripts to PATH, ignore the following error message and then re-run .\Install-RequiredModule.ps1. Of course, one can/should learn how to add the folder to your PATH the hard way, but I kept running into roadblocks left and right (wish i would have seen this issue sooner!)

phoenixtekk commented 1 year ago

Hello, I'm getting the following error when just starting to use this process to use the builder. What could be the problem here? Please, Thanks. Lacy

PS D:\OneDrive\OneDrive - Phoenixtekk\Documents\GitHub\ModuleBuilder> ./Install-RequiredModule.ps1 New-PSGetItemInfo : Cannot convert value "1.4.0-performance0041" to type "System.Version". Error: "Input string was not in a correct format." At C:\Program Files (x86)\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1399 char:30

Jaykul commented 1 year ago

@phoenixtekk that's a totally different problem.

You should be able to just Install-Module ModuleBuilder instead of starting from the source of ModuleBuilder...

But if you want to build it from source, the problem you're having is that the oldest, original version of PowerShellGet can't handle preview version numbers, and doesn't know to ask the gallery not to return them in the list. I would have worked around that in the Install-RequiredModule script, but it's extremely rare to see that version nowadays.

To fix it, you just need to install the latest version of PowerShellGet:

Install-Module PowerShellGet -Force

You may need to add -AllowClobber -SkipPublisherCheck to that, but I don't think so.

Then, you need to use that new version of PowerShellGet -- safe thing is to just restart PowerShell.

The simple fix is to Install