WebAdministration Module Won't Load in PowerShell 5.1

Mike Schulman 21 Reputation points
2021-10-13T21:04:25.207+00:00

I'm trying to load the WebAdministration module in PowerShell 5.1 on quite a few servers, mostly 2012R2, but also about 10 2016. All have IIS and the IIS tools installed, and I'm an administrator on all of the servers. When I import the module from my profile on startup (all of my PowerShell shortcuts run in administrator mode), I get the following error:

Import-Module : Arithmetic operation resulted in an overflow.
At C:\Users\schmi5j\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:126 char:1
+ Import-Module -Name WebAdministration -Scope Global
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], OverflowException
    + FullyQualifiedErrorId : ProviderStartException,Microsoft.PowerShell.Commands.ImportModuleCommand

If I load it manually after starting PowerShell, it appears to load fine (using -verbose shows the entire list of cmdlets installing). However, if i try to run any of the cmdlets, I get this error (using get-website as an example):

get-website : Cannot find a provider with the name 'WebAdministration'.
At line:1 char:1
+ get-website
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (WebAdministration:String) [Get-Website], ProviderNotFoundExce 
   ption
    + FullyQualifiedErrorId : ProviderNotFound,Microsoft.IIs.PowerShell.Provider.GetWebsiteCommand

And it's right, if I run Get-PSProvider, WebAdministration is not listed. Any idea what's wrong?

Internet Information Services
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,389 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 48,826 Reputation points
    2021-10-13T21:29:43.497+00:00

    An early thought is that you have a custom PS repository that is getting in the way. Run get-psrepository to see if there are any repos registered other than PSGallery. Next I might recommend you pass the -Verbose flag as part of your profile call to see what is potentially going on.

    You shouldn't need to specify the -Scope global or -global parameters for the command as this is the default when called from a script or the command line already. This shouldn't be the cause of your issue but just one less thing to worry about.

    The second thing I wonder about is a bad module. Run Get-Module Web* to see what the actual module is and ensure it is the correct version and contains the correct commands. If it doesn't then install it again. Normally, I believe, this is installed as part of IIS features when you install the Management Tools for IIS. You can confirm this using Get-Module -ListAvailable.

    I should also note that it generally isn't necessary to call Import-Module anymore. As of PS 3 if a module is installed then PS will auto load it when you use a command the first time from it. Thus explicit imports are only necessary for modules that haven't already been installed before.

    0 comments No comments

0 additional answers

Sort by: Most helpful