Error 80040154 when working with WebAdministration
I like it from time to time to write in PowerShell. Mostly administrative tasks and deployment. In this article I want to tell you about one interesting problem associated with the operation of the module WebAdministration. So, the crux of the problem: when you run any cmdlet from the module with the error:
The script is run on 64-bit Windows 7. And that is the key. But before proceeding to describe the solutions, I'd like to say a few words about the infrastructure that uses PowerShell scripts. The most frequently used scripts (for example, creating and setting up a local website, creating queues etc.) issued in the form of module functions. In this module, the developer can load into PowerShell session and use the exported functions in the console. But for them to make a wrapper in the form of batch files to run just a click. If you are using them and found this problem. BUT only provided that the batch file is started from Total Commander.
An example of a command that calls the cmdlet Get-WebSite to list all local sites:


Well it looks good. Now try to run the same batch file in Total Commander:


When it was released the 64-bit version of Windows, libraries, pre-existing, has not been renamed. They adapted, recompiled and left to live in the %windir%\System32 folder. And their 32-bit counterparts moved into the directory %windir%\SysWOW64. Now, when a 32-bit process tries to access files in the %windir%\System32, the system automatically redirects call %windir%\SysWOW64. In that case, if a 32-bit process need access to the directory %windir%\System32 folder, he can access it via the alias in the %windir%\Sysnative. Such a call will not be forwarded.
Launching the script from Total Commander, we are launching the 32-bit version of PowerShell, for which the WebAdministration module is not registered correctly for some reason. Or it can be registered only for one architecture? Unfortunately, finding the exact reason I failed.
Anyway we have valuable information. Using the %windir%\Sysnative to run the required version of PowerShell and use all the features of WebAdministration. But note that %windir%\Sysnative exists only in 32-bit mode. The final batch file looks like:
This script will run 64-bit PowerShell from TotalCommander, and from Far, from Windows Explorer (what was tested). In a 32-bit OS as well with no problems.
A few notes:
note 1. Instead of the WebAdministration module, you can use ServerManager from the Assembly Microsoft.Web.Administration.dll. To read about the use in this state.
note 2. Maybe Total Commander can be adjusted so that it ran %windir%\System32\cmd.exe but I have these options is not found.
note 3. It's not like a local problem, because the error appeared on all machines on which network I tried to run the script. I am far from administration of LAN networks are likely to change some settings in the domain?
Thank you for your attention!
Article based on information from habrahabr.ru
Cannot retrieve the dynamic parameters for the cmdlet.
Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154.
The script is run on 64-bit Windows 7. And that is the key. But before proceeding to describe the solutions, I'd like to say a few words about the infrastructure that uses PowerShell scripts. The most frequently used scripts (for example, creating and setting up a local website, creating queues etc.) issued in the form of module functions. In this module, the developer can load into PowerShell session and use the exported functions in the console. But for them to make a wrapper in the form of batch files to run just a click. If you are using them and found this problem. BUT only provided that the batch file is started from Total Commander.
An example of a command that calls the cmdlet Get-WebSite to list all local sites:
powershell-noexit -command "& { Import-Module WebAdministration; Get-WebSite }"
* This source code was highlighted with Source Code Highlighter.
Let's save it to a file and try to run it from Windows Explorer. With the flag “-noexit” session will not end after you run the command and we will have time to perform the running process using Process Explorer. We saw the list of local sites, and in Process Explorer I looked at the properties of the process:

Well it looks good. Now try to run the same batch file in Total Commander:


When it was released the 64-bit version of Windows, libraries, pre-existing, has not been renamed. They adapted, recompiled and left to live in the %windir%\System32 folder. And their 32-bit counterparts moved into the directory %windir%\SysWOW64. Now, when a 32-bit process tries to access files in the %windir%\System32, the system automatically redirects call %windir%\SysWOW64. In that case, if a 32-bit process need access to the directory %windir%\System32 folder, he can access it via the alias in the %windir%\Sysnative. Such a call will not be forwarded.
Launching the script from Total Commander, we are launching the 32-bit version of PowerShell, for which the WebAdministration module is not registered correctly for some reason. Or it can be registered only for one architecture? Unfortunately, finding the exact reason I failed.
Anyway we have valuable information. Using the %windir%\Sysnative to run the required version of PowerShell and use all the features of WebAdministration. But note that %windir%\Sysnative exists only in 32-bit mode. The final batch file looks like:
if not exist %windir%\Sysnative\nul goto 64bit
set ps="%windir%\Sysnative\WindowsPowerShell\v1.0\powershell.exe"
goto start
:64bit
set ps="%windir%\System32\WindowsPowerShell\v1.0\powershell.exe"
:start
%ps% -noexit -command "& { Import-Module WebAdministration; Get-WebSite }"
* This source code was highlighted with Source Code Highlighter.
This script will run 64-bit PowerShell from TotalCommander, and from Far, from Windows Explorer (what was tested). In a 32-bit OS as well with no problems.
A few notes:
note 1. Instead of the WebAdministration module, you can use ServerManager from the Assembly Microsoft.Web.Administration.dll. To read about the use in this state.
note 2. Maybe Total Commander can be adjusted so that it ran %windir%\System32\cmd.exe but I have these options is not found.
note 3. It's not like a local problem, because the error appeared on all machines on which network I tried to run the script. I am far from administration of LAN networks are likely to change some settings in the domain?
Thank you for your attention!
Комментарии
Отправить комментарий