I'm coming onto a project that uses PowerShell
to script the build. The build makes use of the WebAdministration
module to manage the local IIS instance. When I run the build script the following error is thrown when trying to import WebAdministration
.
Error: 06/29/2016 17:28:35: At
C:\dev\src\nib-ravendb\build\ConfigureIis.ps1:10 char:1 +
Import-Module WebAdministration + ~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
[<<==>>] Exception: The specified module 'WebAdministration' was not
loaded because no valid module file was fo und in any module
directory. ERROR: 1
How ever when I run Import-Module WebAdministration
at the PowerShell
command line the module is imported and I can use features from it. Subsequently running the build script still fails.
I have IIS 7.5
and PowerShell 4
Does anyone have an idea why this import would be failing in the script but not at the command line, and how to fix it?
Best Answer
For servers you need to install the role
Management Tools
underWeb Server (IIS)
to use theWebAdministration
module. To see if you have the module available useGet-Module -ListAvailable
.For
Windows 7
to10
you will need to install the featureIIS Management Scripts and tools
underInternet Information Services
>>Web Management Tools
.You could try manually locating the
WebAdministration
.psd1 file and then import it. Use$env:psmodulepath
to help locate where your modules are stored then run:If
Server 2008
you could try the following but this may not work on 2012 and upwards:Note You will need to run the script with administrator rights to be able to load the
WebAdministration
module withImport-Module
orAdd-PSSnapin
.Also check that you have
PowerShell
's execution Policy set toUnrestricted
:You might want to see this Question.