rmbolger / Posh-IBWAPI

PowerShell module for interacting with the Infoblox WAPI (REST API).
MIT License
54 stars 8 forks source link

Import-Module error on installation with iex #14

Closed frankhecker closed 7 years ago

frankhecker commented 7 years ago

I'm trying to duplicate the environment of my customers, who typically have restrictions on what software they can install (or whether they can install software at all). So I'm trying to install Posh-WBAPI on PowerShell 4.0 (on Windows 7 SP1), matching my customer's Windows 8.1 environment, using the iex-based method documented in the README.

When doing so in a brand-new PowerShell session just now, the software downloads properly, but I get the following error after the message "Renaming folder":

Import-Module : The specified module 'Posh-IBWAPI' was not loaded because no valid module file was found in any module directory.
At line:25 char:5
+     Import-Module -Name Posh-WBAPI
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : Resourceunavailable: (Posh-WBAPI:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Module has been installed

Is this a fatal error? Is there some other command I should be running?

frankhecker commented 7 years ago

OK, I figured it out. You're assuming that the user has set the PSModulePath environment variable to include the directory $env:HOMEDRIVE$env:HOMEPATH\Documents\WindowsPowerShell\Modules. You don't mention that in the README; is this something that's done automatically in some versions or Windows and/or PowerShell?

I suggest noting the need to have PSModulePath set properly, and also linking to an explanation of how to set that variable, for example, https://msdn.microsoft.com/en-us/library/dd878326.aspx

In my case I set the PSModulePath variable temporarily as follows:

$env:PSModulePath = $env:PSModulePath + ";$env:HOMEDRIVE$env:HOMEPATH\Documents\WindowsPowerShell\Modules"

and the iex-based installation then worked properly.

frankhecker commented 7 years ago

There's a separate error you get when you try to do a iex-based installation on a stock Windows 10 installation: On Windows 10 the PSModulePath variable is apparently set correctly by default to include $env:HOMEDRIVE$env:HOMEPATH\Documents\WindowsPowerShell\Modules (and it's at the front of the path). However when I run the iex-based install I get the following error:

Import-Module : Errors occurred while loading the format data file:
C:\Users\fhecker\Documents\WindowsPowerShell\Modules\Posh-IBWAPI\Posh-IBWAPI.Format.ps1xml, ,
C:\Users\fhecker\Documents\WindowsPowerShell\Modules\Posh-IBWAPI\Posh-IBWAPI.Format.ps1xml: The file was skipped
because of the following validation exception: File
C:\Users\fhecker\Documents\WindowsPowerShell\Modules\Posh-IBWAPI\Posh-IBWAPI.Format.ps1xml cannot be loaded because
running scripts is disabled on this system. For more information, see about_Execution_Policies at
http://go.microsoft.com/fwlink/?LinkID=135170..
At line:25 char:5
+     Import-Module -Name Posh-IBWAPI
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], RuntimeException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand

In order to fix the problem I had to change the execution policy:

 Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

After doing this the installation worked fine.

I suggest modifying the README file to note the need to set the execution policy appropriately, and linking to https://technet.microsoft.com/en-us/library/ee176961.aspx for instructions on how to do this.

rmbolger commented 7 years ago

This is good feedback, Frank. Thanks. I'll see if I can smooth out the process a bit.

frankhecker commented 7 years ago

Sorry, I'm still learning my way around PowerShell variables. A simpler way to set PSModulePath is to use the $home variable:

 $env:PSModulePath = $env:PSModulePath + ";$home\Documents\WindowsPowerShell\Modules"

This can be put in the file whose location is given by the $profile variable, typically $home\Documents\WindowsPowerShell\Profile.ps1.

rmbolger commented 7 years ago

So the PSModulePath environment variable definitely contains $HOME\Documents\WindowsPowerShell\Modules on the Win7 SP1 and Win8.1 VMs I just spun up. So I modified the readme to include a note about that. I also linked to the page on how to modify it. But it's probably not worth actually explaining how to fix it.

Regarding the execution policy. I added a note about not having it set to Restricted or AllSigned and included an example on how to set it to RemoteSigned for the current user.

I also switched the sections so that the PowerShell gallery install section comes before the development version install section. Ideally, people use the gallery. There are now supported versions of the PowerShellGet module for OSes all the way back to Win7 SP1.