The WebAdministration import module is not loaded from the script, but from the command line

I come to a project that uses PowerShellto script build. The assembly uses a module WebAdministrationto manage the local IIS instance. When I run the build script, the WebAdministrationfollowing error occurs when trying to import .

Error: 06/29/2016 17:28:35: In C: \ dev \ src \ nib-ravendb \ build \ ConfigureIis.ps1: 10 char: 1 + Import module WebAdministration + ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ [<<== →] Exception: The specified "WebAdministration" module was not loaded because no valid module file was in any module directory. ERROR: 1

As always, when I run Import-Module WebAdministrationon the command line PowerShell, the module is imported, and I can use its functions. Subsequently, the execution of the script assembly is still not executed.

I have IIS 7.5andPowerShell 4

Does anyone have an idea why this import will crash in the script, but not on the command line, and how to fix it?

+4
source share
2 answers

In the end there was a problem, something, perhaps chocolate ?, truncated $env:PSModulePathbefore the first record, so the script worked if I typed it, but not in the script.

I found it by registering $env:PSModulePathat various points in the scripts that I ran.

I worked around him reordering entries in $env:PSModulePath.

@Richard .

0

Management Tools Web Server (IIS) WebAdministration. , , Get-Module -ListAvailable.

Windows 7 10 IIS Management Scripts and tools Internet Information ServicesWeb Management Tools.

WebAdministration.psd1, . $env:psmodulepath, , , :

Import-Module -Name 'C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WebAdministration\WebAdministration.psd1' 

Server 2008 , 2012 :

Add-PSSnapin WebAdministration

script , WebAdministration Import-Module Add-PSSnapin.

, ​​ PowerShell: Unrestricted:

Set-ExecutionPolicy unrestricted

, Question.

+6

All Articles