Importing WebAdministration Module in Powershell Host ApplicationRSS

7 replies

Last post Sep 28, 2011 11:37 AM by jasonint32

  • Importing WebAdministration Module in Powershell Host Application

    Dec 08, 2009 04:58 PM|jyoung0001|LINK

    I am new to Powershell, and am not well versed in Windows administration.  I'd like to be able to run some simple Powershell scripts for managing an IIS 7.5 FTP site from within a VB.NET application. 

    I've created a host, and attempted to invoke the commands using the PowerShell class. 

    I am getting the message "file ...WebAdministrationAliases.ps1 cannot be loaded because the execution of scripts is disabled on this system..." message when I attempt to load the WebAdministration Module.

    A few additional notes:

    • I am running on Win2008R2 64bit, IIS7.5, Powershell 2, Visual Studio 2010 Beta 2.
    • I am running as administrator
    • I can run the commands from within Powershell just fine, assuming I run the Set-ExecutionPolicy and Import-Module commands first.
    • I've tried loading the module via both the InitialSessionState.ImportPSModule method, and the AddCommand("Import-Module WebAdministration").
    • I've tried passing Set-ExecutionPolicy Unrestricted via the AddCommand method, but it returns an error message stating that "The term 'Set-ExecutionPolicy Unrestricted' is not recognized as the name of a cmdlet, function, script file, or operable program..."
    • My application is signed.

    I'm sure I'm missing something simple, but I'm at a loss for what to try next to give this application the appropriate permissions.  Any help would be appreciated.

    PowerShell IIS Powershell IIS7 powerShell script FTP WebAdministration IIS 7.5

  • Re: Importing WebAdministration Module in Powershell Host Application

    Dec 10, 2009 04:57 AM|Leo Tang - MSFT|LINK

    Hi,

    Please try add the cmdlet to the pipeline, then add the arguments for the cmdlet immediately after the cmdlet is added. It looks like:

    AddCommand("Set-ExecutionPolicy")
    AddArgument("Unrestricted")

    Please mark the replies as answers if they help or unmark if not.
    Feedback to us


  • Re: Importing WebAdministration Module in Powershell Host Application

    Dec 10, 2009 11:12 AM|jyoung0001|LINK

    Thank you, that did seem to get me farther along.  Now I am running into the same issue listed in this thread:

     http://forums.iis.net/t/1161177.aspx

    My current image of 2008R2 had the Beta products for Office and SharePoint installed, as well as the Beta2 version of VS 2010.  I'm rolling back to an image prior to the Beta installs, and am going to try with Visual Studio 2008.

  • Re: Importing WebAdministration Module in Powershell Host Application

    Dec 11, 2009 11:29 AM|jyoung0001|LINK

    I tried the same code on a clean Win2008R2 system using Visual Studio 2008 SP1, and got the same result.  I am still getting the error "Cannot retrieve the dynamic paramters for the cmdlet.  Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154".  I've checked the registry, and that CLSID is registered, and the .dll it is pointing to is on the system.

    At this point I'm losing confidence in the PowerShell approach.  I simply want to create a virtual directory in IIS 7.5 via .NET code.  If I understand correctly, using Active Directory no longer works with IIS 7.5 for this.  What are the alternative techniques for this, can anyone point me in the right direction?

  • Re: Importing WebAdministration Module in Powershell Host Application

    Dec 13, 2009 08:00 PM|philip.beadle|LINK

    I have the same issue. I want to create a new IIS site as part of my automation testing but cant get Powershell to load the WebAdministration module from C#.
    Philip Beadle (DotNetNuke Trustee)

    My Blog

    My DNN Blog

    (If this has answered your question, Mark as Answer)
  • Re: Importing WebAdministration Module in Powershell Host Application

    Dec 16, 2009 11:06 AM|jyoung0001|LINK

    I was not able to resolve the issues I was having with the powershell approach.  I've switched and am now using the ServerManager class that is part of the Microsoft.Web.Administration dll.  This is working so far, and is probably a cleaner solution for what I was trying to do anyway.  Specifically, the other thread I referenced earlier and the post below led me down the path I'm using now.

     http://blogs.msdn.com/carlosag/archive/2006/04/17/MicrosoftWebAdministration.aspx

  • Re: Importing WebAdministration Module in Powershell Host Application

    Apr 20, 2011 04:07 PM|ghouston|LINK

    I figured out the issue...

    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 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

    The C# .Net application is hosting Powershell and running a powershell script.  The script is calling a WebAdministration cmdlet.  The cmdlet call causes Powershell to load Microsoft.AppHostQueryProcessor (AppHostNavigators.dll).  This will fail when the .Net program's platform target doesn't match the machine's CPU.   In my case, the Platform target was "x86".  When run on an x64 Windows 2008 R2 server it can't find the x64 dll.

    The fix is to make sure .Net application is built with the correct Platform target ("Any CPU" is the best choice in most situations).

     

    PowerShell WebAdministration C# .Net

  • Re: Importing WebAdministration Module in Powershell Host Application

    Sep 28, 2011 11:37 AM|jasonint32|LINK

    For those of you experiencing this issue just trying to run some WebAdministration code in a regular powershell window like I was, the following fix worked for me.  It is essentially the same logic as the previous reply but in a somewhat different context.  Running 64bit powershell has a problem executing 32bit COM objects like WebAdministration I guess.  So, open up a powershell window from here instead:

     C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

     I also set my execution policy to unrestricted, though I'm not sure if that was necessary. 

     Now I can run WebAdministration commands against a remote server.