Giter Club home page Giter Club logo

installmodulefromgithub's Introduction

Install a PowerShell Module from GitHub

Not all PowerShell Modules are published to the PowerShellGallery but are hosted on GitHub.

Read the blog post

Changes

1.6.0

via #25

  • on non-unix platforms, fixed the psd1 file search join-path on line 87 was joining two full paths, which is not a valid result.

1.5.0

Thank you to Max Renner for the pull request.

  • Use [System.Environment]::OSVersion.Platform -eq "Unix" as a catch all for non-windows systems
  • Replaced the hard coded Module paths assigned to $dest with environment variables instead.
  • Added if logic for Windows vs Non-Windows machines in assigning $psd1 and in the final Copy-Item statement.

1.4.0

v 0.5.0

In Action

image

installmodulefromgithub's People

Contributors

dfinke avatar jgigler avatar jonathanpitre avatar mivalsten avatar montereyharris avatar montereyharris-mag avatar rennerom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

installmodulefromgithub's Issues

Invoke-RestMethod errors

Cmdlet:
Find-Module windows-screenfetch | Install-ModuleFromGitHub
Errors:

Invoke-RestMethod: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:47                                                                                                                    Line |                                                                                                                    47 |  …             Invoke-RestMethod $url -OutFile $OutFile -Headers $header …                                          |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                              | {"message":"Not Found","documentation_url":"https://developer.github.com/v3"}                                                                                                                                                            Unblock-File: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:49 Line |                                                                                                                    49 |                    Unblock-File $OutFile                                                                              |                    ~~~~~~~~~~~~~~~~~~~~~                                                                              | Cannot find path 'C:\Users\Yihua\AppData\Local\Temp\Windows-screenFetch.zip' because it does not exist.                                                                                                                                  Get-FileHash: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:52 Line |                                                                                                                    52 |                  $fileHash = $(Get-FileHash -Path $OutFile).hash                                                      |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                            | Cannot find path 'C:\Users\Yihua\AppData\Local\Temp\Windows-screenFetch.zip' because it does not exist.                                                                                                                                  Expand-Archive: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:55                                                                                                                       Line |                                                                                                                    55 |  …             Expand-Archive -Path $OutFile -DestinationPath $tmpDir -F …                                          |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                              | The path 'C:\Users\Yihua\AppData\Local\Temp\Windows-screenFetch.zip' either does not exist or is not a                | valid file system path.

Join-Path: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:73
Line |
  73 |  … hildItem (Join-Path -Path $tmpDir -ChildPath $unzippedArchive) -Inclu …
     |                                                 ~~~~~~~~~~~~~~~~
     | Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ChildPath'.
     | Specified method is not supported.

Join-Path: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:81
Line |
  81 |  … y-Item "$(Join-Path -Path $tmpDir -ChildPath $unzippedArchive)" $dest …
     |                                                 ~~~~~~~~~~~~~~~~
     | Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ChildPath'.
     | Specified method is not supported.
                                                                                                                        Copy-Item: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:81    Line |                                                                                                                    81 |  … = Copy-Item "$(Join-Path -Path $tmpDir -ChildPath $unzippedArchive)"  …                                          |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                               | Cannot bind argument to parameter 'Path' because it is an empty string.

Cmdlet:
Install-ModuleFromGithub -GitHubRepo JulianChow94/Windows-screenFetch
Errors:

Invoke-RestMethod: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:47                                                                                                                    Line |                                                                                                                    47 |  …             Invoke-RestMethod $url -OutFile $OutFile -Headers $header …                                          |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                              | Unable to read data from the transport connection: 远程主机强迫关闭了一个现有的连接。.                                                                                                                                                   Unblock-File: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:49 Line |                                                                                                                    49 |                    Unblock-File $OutFile                                                                              |                    ~~~~~~~~~~~~~~~~~~~~~                                                                              | Cannot find path 'C:\Users\Yihua\AppData\Local\Temp\Windows-screenFetch.zip' because it does not exist.                                                                                                                                  Get-FileHash: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:52 Line |                                                                                                                    52 |                  $fileHash = $(Get-FileHash -Path $OutFile).hash                                                      |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                            | Cannot find path 'C:\Users\Yihua\AppData\Local\Temp\Windows-screenFetch.zip' because it does not exist.                                                                                                                                  Expand-Archive: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:55                                                                                                                       Line |                                                                                                                    55 |  …             Expand-Archive -Path $OutFile -DestinationPath $tmpDir -F …                                          |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                              | The path 'C:\Users\Yihua\AppData\Local\Temp\Windows-screenFetch.zip' either does not exist or is not a                | valid file system path.

Join-Path: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:73
Line |
  73 |  … hildItem (Join-Path -Path $tmpDir -ChildPath $unzippedArchive) -Inclu …
     |                                                 ~~~~~~~~~~~~~~~~
     | Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ChildPath'.
     | Specified method is not supported.

Join-Path: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:81
Line |
  81 |  … y-Item "$(Join-Path -Path $tmpDir -ChildPath $unzippedArchive)" $dest …
     |                                                 ~~~~~~~~~~~~~~~~
     | Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ChildPath'.
     | Specified method is not supported.

Copy-Item: C:\Users\Yihua\Documents\PowerShell\Modules\InstallModuleFromGitHub\1.3.0\InstallModuleFromGitHub.psm1:81
Line |
  81 |  … = Copy-Item "$(Join-Path -Path $tmpDir -ChildPath $unzippedArchive)"  …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot bind argument to parameter 'Path' because it is an empty string.

PowerShell version: 7.0.1

What are the prereqs on the GitHub Repo side for this to work pls?

(this may not be the right area to send this, if so, please forgive me - but I am really stumped... hoping someone can point me in the right direction pls!!)

I LOVE the idea of this, and I can get this to work for your [dfinke/ImportExcel] from the blog article.

My dilemma, is that I cannot figure out what the requirements are for the Guthub Repo side to allow this to work - I know I am missing something.... I have tried on a private and a public repo (though a private repo will be my ultimate need for this), and have compared what I see in your dfinke/ImportExcel repo - but I am just not seeing what is missing...?
What I mean is - is there something on the GitHub Repo that this is specifically looking for?
i.e. I think it's something to do with how the module is getting published to the Repo, but I have gone through every docs and resource I can find, and just cannot find good and concrete information on the whole process of publishing a module to a repo ...

If not, can you suggest any good tutorials on how a module 'should' be published to the Repo (correctly), where this will be able to workl?
I appreciate ANY help anyone can send my way!!

The remote server returned an error

I'm unable to get this to work. I have a 'Hello World' test module in my Github repository but get an error

Cmdlet :
Install-ModuleFromGitHub -GitHubRepo /AyanMullick/test/master/HelloWorld.psm1

Error:
Invoke-RestMethod : The remote server returned an error: (404) Not Found. At C:\Program files\WindowsPowerShell\Modules\InstallModuleFromGitHub\1.1\InstallModuleFromGitHub.psm1:40 char:19 Invoke-RestMethod $url -OutFile $OutFile

Add support to private repositories

Instead of asking me my login and password, this module is failing when trying to access a private github repository:

A solicitação foi anulada: Não foi possível criar um canal seguro para SSL/TLS.
No C:\Program Files\WindowsPowerShell\Modules\InstallModuleFromGitHub\1.2\InstallModuleFromGitHub.psm1:40 caractere:19
+                   Invoke-RestMethod $url -OutFile $OutFile
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Add a Github 0.4 release

Is there a chance you could add add a 0.4 release.zip?

That way I can Invoke-Webrequest the zip file, save it, unblock it, force install it to the modules directory. It's a little simpler install for the enterprise with a collage of Windows 7 machines in various states of consistency.

I find it works well for my internal releases. I create a package of files, zip it all up, copy it to an internal IIS web site.

Publish with bug fixes?

There are 3 commits that have been merged but no version has been released containing them

Fix module installation path

There's an issue with the latest release. The installation path for the module is wrong. It contains the parent folder instead of just the content of the archive.

image

Here's the fix:

Line 82
$null = Copy-Item "$(Join-Path -Path $tmpDir -ChildPath $unzippedArchive\*)" $dest -Recurse -Force

Doesn't appear to work any more?

On PowerShell 5.1, latest Windows 10.

Looks like the GitHub URLs are no longer valid?

Install-Module InstallModuleFromGitHub

Find-Module nameit | Install-ModuleFromGitHub

Invoke-RestMethod : {"message":"Not Found","documentation_url":"https://docs.github.com/rest"}
At C:\Program Files\WindowsPowerShell\Modules\InstallModuleFromGitHub\1.5.0\InstallModuleFromGitHub.psm1:48 char:17
+ ...             Invoke-RestMethod $url -OutFile $OutFile -Headers $header ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Issue on join-path

Seeing an issue with the import module failing due to join path being unable to convert system.object to string

Branch names with '/' in them cause errors due to unescaped use as file path

PS> Install-ModuleFromGitHub -GitHubRepo NetzwergX/Windows-Screenfetch -Branch 'fix/Get-Uptime' -Debug                  
Invoke-RestMethod: <redacted>\PowerShell\Modules\InstallModuleFromGitHub\0.3\InstallModuleFromGitHub.psm1:28                                                                                                                   Line |                                                                                                                    28 |                  Invoke-RestMethod $url -OutFile $OutFile                                                             |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                             | Could not find a part of the path '<redacted>\win-screenfetch\fix\Get-Uptime.zip'.                                                                                                                                                       Unblock-File: <redacted>\PowerShell\Modules\InstallModuleFromGitHub\0.3\InstallModuleFromGitHub.psm1:29
Line |
  29 |                  Unblock-File $OutFile
     |                  ~~~~~~~~~~~~~~~~~~~~~
     | Cannot find path '<redacted>\win-screenfetch\fix\Get-Uptime.zip' because it does not exist.

Expand-Archive: <redacted>\PowerShell\Modules\InstallModuleFromGitHub\0.3\InstallModuleFromGitHub.psm1:30
Line |
  30 |  …             Expand-Archive -Path $OutFile -DestinationPath $pwd -Forc …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The path '<redacted>\win-screenfetch\fix/Get-Uptime.zip' either does not exist or is not a valid file
     | system path.

Get-ChildItem: <redacted>\PowerShell\Modules\InstallModuleFromGitHub\0.3\InstallModuleFromGitHub.psm1:36
Line |                                                                                                                    
  36 |                  $psd1=ls $targetModule *.psd1                                                                        
     |                        ~~~~~~~~~~~~~~~~~~~~~~~                                                                       
     | Cannot find path '<redacted>\win-screenfetch\Windows-Screenfetch-fix\Get-Uptime' because it does not                  
     | exist.

Using the branch name for the file doesn't work when the branch contains a slash. Using branches like release/x, feature/x or fix/x is not uncommon and should be supported.

Expand-Archive error

Hello,

I was trying to use your script to install some random powershell module on github.
I stumbled upon an error that happens during the Expand-Archive phase.
It looks like using a file hash generates as a folder name that is too long for windows (well I guess).
I did have to do some debugging because the Expand-Archive cmdlet does not show the correct error message when the path is too loong => PowerShell/Microsoft.PowerShell.Archive#69
To fix it temporarily I replaced line 53 of InstallModuleFromGitHub.psm1 $tmpDir = "$tmpDir/$fileHash" with $tmpDir = "$tmpDir/$targetModuleName" directly in C:\Program Files\WindowsPowerShell\Modules\InstallModuleFromGitHub\1.4.0.

cant install github branch

PS C:\WINDOWS\system32> Install-Module -Name InstallModuleFromGitHub Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): a
PS C:\WINDOWS\system32> Install-ModuleFromGitHub -githubrepo "microsoft/winget-cli" -branch "master"
Join-Path : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ChildPath'. Specified
method is not supported.
At C:\Program Files\WindowsPowerShell\Modules\InstallModuleFromGitHub\1.6.0\InstallModuleFromGitHub.psm1:94 char:62

  • ... $dest = Join-Path -Path $dest -ChildPath $ModuleVersion
  •                                                        ~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [Join-Path], ParameterBindingException
    • FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.JoinPathCommand

Copy-Item : Cannot find path 'C:\Users\byran\AppData\Local\Temp\3F7EC4B0474BBFB7A40FE691848AA28D143B4954AD76A1A7C19B9C2
71A2499F2\microsoft-winget-cli-5d0e02b\src\PowerShell\Microsoft.WinGet.Client\Module C:\Users\byran\AppData\Local\Temp
3F7EC4B0474BBFB7A40FE691848AA28D143B4954AD76A1A7C19B9C271A2499F2\microsoft-winget-cli-5d0e02b\src\PowerShell\Microsoft.
WinGet.DSC C:\Users\byran\AppData\Local\Temp\3F7EC4B0474BBFB7A40FE691848AA28D143B4954AD76A1A7C19B9C271A2499F2\microsoft
-winget-cli-5d0e02b\tools\PowerShell\Microsoft.WinGet\src C:\Users\byran\AppData\Local\Temp\3F7EC4B0474BBFB7A40FE691848
AA28D143B4954AD76A1A7C19B9C271A2499F2\microsoft-winget-cli-5d0e02b\tools\PowerShell\Microsoft.WinGet.Client\crescendo C
:\Users\byran\AppData\Local\Temp\3F7EC4B0474BBFB7A40FE691848AA28D143B4954AD76A1A7C19B9C271A2499F2\microsoft-winget-cli-
5d0e02b\tools\PowerShell\Microsoft.WinGet.Client\src' because it does not exist.
At C:\Program Files\WindowsPowerShell\Modules\InstallModuleFromGitHub\1.6.0\InstallModuleFromGitHub.psm1:104 char:29

  • ... $null = Copy-Item "$sourcePath*" $dest -Force -Recurse
  •                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (C:\Users\byran...nGet.Client\src:String) [Copy-Item], ItemNotFoundExce
      ption
    • FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand

Failing to copy over mulitple folders inside of PSModule

If there are multiple folders it seems that it fails to copy over with this error

writeErrorStream : True
PSMessageDetails :
Exception : System.Management.Automation.PSArgumentException: Container cannot be copied onto existing
leaf item.
TargetObject : C:\Users\mharris\AppData\Local\Temp\omsagent-master\views
CategoryInfo : InvalidArgument: (C:\Users\mharri...nt-master\views:String) [Copy-Item], PSArgumentException
FullyQualifiedErrorId : CopyContainerItemToLeafError,Microsoft.PowerShell.Commands.CopyItemCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at Install-ModuleFromGitHub, C:\Program
Files\WindowsPowerShell\Modules\InstallModuleFromGitHub\1.1\InstallModuleFromGitHub.psm1: line
70
PipelineIterationInfo : {0, 1}

Errors on Windows

This worked great on Mac but I encountered errors on Windows. It errors on the Get-Childitem and then the Copy-Item towards the end of the process. Both are contained in an if statement to check the operating system. In testing, it appears these if statements are not necessary. When I stepped through and used the UNIX versions for each of the Get-ChildItem and Copy-Item commands they worked as expected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.