Powershell - Error creating ServerManager object after Windows updates

Hi

I have a powershell deployment script that downloads files from svn to a directory and then updates IIS settings to specify the site in a new folder. It works fine until some updates have been made on the server. Now when I try to run the script, errors on

[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration") $serverManager = New-Object Microsoft.Web.Administration.ServerManager 

Error

 New-Object : Exception calling ".ctor" with "0" argument(s): "Retrieving the COM class factory for component with CLSID {B15183DD-75F9-42DF-8E57-C8B57692F134} failed due to the following error: 80040154." At C:\Users\administrator.LAYERXNETWORKS\AppData\Local\Temp\2\e72ec49f-353f-4dc0-877c-ef67f6b49bab.ps1:2 char:28 + $serverManager = New-Object <<<< Microsoft.Web.Administration.ServerManager + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand 

I read that this error is usually caused by the fact that the class is not installed.

The server is running Windows 2008 R2 with IIS 7.5

+4
source share
2 answers

Make sure you download the correct beaten version of PowerShell. If you use the 64-bit version, you will get the described exception.

You need to use the 32-bit (Windows PowerShell (x86)) version of PowerShell to use Microsoft.Web.Administration .

+3
source

As an additional answer, I discovered problems using the x86 powershell console and eventually found that using

 [System.Reflection.Assembly]::LoadFrom( "C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll" ) 

but not

 [Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration") 

This is normal.

+2
source

Source: https://habr.com/ru/post/1346166/


All Articles