PowerShell: Import-Module IISAdministration Fails With "Could not load file or assembly 'Microsoft.Web.Administration..."

Prerequisites

Steps to reproduce

On Windows, run the following script in PowerShell 7.2.1:

Install-Module -Name IISAdministration
Import-Module IISAdministration
Get-Module -ListAvailable

I have confirmed on a VM running 19042 that the Windows 10 build is not a factor as far as I can tell, because on a 20H2 VM I still see the problem behavior. I have also enabled IIS Management Console and IIS Management Scripts and Tools. The bulk of the documentation I could find referred to earlier versions of PowerShell 7 not supporting IISAdministration, but this doesn’t seem to apply to 7.2.1 - if it did globally, I wouldn’t have myself and multiple other team members running the scripts with no issues. I appreciate any help!

I did see in issue #13818 the reporter was told to look in the https://github.com/PowerShell/PowerShellModuleCoverage repo and I reported the issue there as well, but then I saw the repo appears to be defunct. Its last commit was literally 4 years ago. ALl the other issues I can find reported for IISAdministration and PowerShell Core / 7 are at least two years old and refer specifically to earlier versions of PowerShell being incompatible, but I can see from the fact that the module works on several developer machines in my department that is no longer true.

Expected behavior

The import should succeed and the module should be listed:

Script     1.1.0.0               IISAdministration                   Core,Desk {Get-IISServerManager, Set-IISConfigAtt…

Actual behavior

The import fails with the following error:

Import-Module: Could not load file or assembly 'Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

The system cannot find the file specified.

The Get-Module list shows no cmdlets associated with IISAdministration:

Script     1.1.0.0               IISAdministration                   Core,Desk

Error details

No response

Environment data

On the machine exhibiting the problem behavior:

PS C:\Users\thoma> $PSVersiontable

Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

On the machine working successfully:

PS C:\Users\thomas.parikkaADM> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

Another year later and still no response…

I found an issue with at least one installation of IIS and this module. For some reason, in the C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules folder the IISAdministration module was installed possibly by the IIS feature installation, and the files are set to read-only and execute for permissions outside of the TrustedInstaller owner permissions. If it is installed with Install-Module, the folder C:\Program Files\PowerShell\Modules is used and installed into the versioned folder there.

The workaround I figured out is a multi-step process.

  1. Install the module: Install-Module -Name IISAdministration -Scope AllUsers -AllowClobber
  2. Copy the version folder (current version as of this comment: 1.1.0.0) to C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\IISAdministration
  3. Uninstall the module: Uninstall-Module -Name IISAdministration -AllVersions
  4. Import the module with the -RequiredVersion parameter: Import-Module -Name IISAdministration -RequiredVersion 1.1.0.0

This works perfectly, although very annoying. Note that if you do not use the -RequiredVersion parameter, you will get the previous version. This version and the previous version do not show on Get-Module -ListAvailable because, for some reason, PS7+ ignores the PSModulePath value of C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules (bug or expected behavior? I’m leaning towards the latter as you might get some very unexpected results from very old modules in PS7+). Import-Module does not ignore that path.

@doctordns Unfortunately, I did not had any luck with this method. I cannot replace the existing files in C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\IISAdministration

All my tests are done in Windows Server 2019 v1809 build 17763.4499

This version of the OS come with version 1.0 of IISAdministration and for multiple reasons I need the version 1.1.0.0 The command Import-Module IISAdministration -RequiredVersion 1.1.0.0 (With or without -SkipEditionCheck) fail. So I need to install the latest version present in the PowerShell Gallery.

As mentioned above, install the module in PS7 with the following command:

Install-Module -Name IISAdministration -Scope AllUsers -AllowClobber

After the installation:

Import-Module IISAdministration -RequiredVersion 1.1.0.0
Import-Module: Could not load file or assembly 'Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

To solve this, copy C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll in the directory where IISAdministration 1.1.0.0 is installed: C:\Program Files\PowerShell\Modules\IISAdministration\1.1.0.0

Now import the module again and it will work:

PS C:\Windows\System32> Import-Module IISAdministration -RequiredVersion 1.1.0.0
PS C:\Windows\System32> Get-Module -List IISAdministration

    Directory: C:\Program Files\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     1.1.0.0               IISAdministration                   Desk

I hope this can help.