locked
Is it possible to manage IISExpress with WebAdministration (Poweshell)? RRS feed

  • Question

  • User-2058010767 posted

    I wonder if managing IISExpress with Web Server (IIS) Administration Cmdlets  https://technet.microsoft.com/en-us/library/hh867899(v=wps.630).aspx is supported.

    I added just "IIS Management Scripts and Tools" under  "Turn Windows features on or off",  " Web Management Tools" on Win7. I do not have IIS installed, just IISExpress.

    I can import Web Administration module:

    Import-Module webadministration

    I can see it cmdlets:

    Get-Command -pssnapin webadministration

    But running this

    Get-Website -Name "Default Web Site"

    fails with "Get-Website : Cannot find a provider with the name 'WebAdministration'."

    Is it not supposed to work with IISExpress?

     

    Thursday, June 25, 2015 10:12 AM

Answers

  • User-1939905867 posted

    @stanb

    I totally hear you. I don't like using appcmd.exe at all. If you ever used the PowerShell cmdlets, you never want to go back.

    Here is a hack that may work for you:

    I still think the PowerShell cmdlets only work against the full IIS, so what you can try is copying your Express configuration to full IIS, change it with PowerShell and copy it back. 

    First install the proper IIS including the scripting tools.

    Before you want to make an IIS Express configuration change, run the following as admin:

    Move-Item $env:SystemRoot\System32\inetsrv\config\applicationhost.config -Destination $env:SystemRoot\System32\inetsrv\config\applicationhost.iis -Verbose
    Copy-Item $env:USERPROFILE\Documents\IISExpress\config\applicationhost.config -Destination $env:SystemRoot\System32\inetsrv\config\applicationhost.config -Verbose

    Now make your changes using the PowerShell cmdlets or even the IIS Manager, when done, move the file back:

    Move-Item $env:SystemRoot\System32\inetsrv\config\applicationhost.config -Destination $env:USERPROFILE\Documents\IISExpress\config\applicationhost.config -Force -Verbose
    Move-Item $env:SystemRoot\System32\inetsrv\config\applicationhost.iis -Destination $env:SystemRoot\System32\inetsrv\config\applicationhost.config -Verbose
    

    I only tested this quickly with IIS Express 8 on Server 2012 R2 but it seems to work.

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Thursday, June 25, 2015 5:38 PM

All replies

  • User-1499466209 posted

    Hi,

    the Web Server (IIS) Administration Cmdlets work with IISExpress.

    I guess you don't have enough permissions to use Get-Website. Can you try with an admin account and/or in a PowerShell console run as administrator

    Thursday, June 25, 2015 10:34 AM
  • User-1939905867 posted

    Really? 

    I was pretty sure they don't.

    How do you tell the cmdlets to use IIS Express and not IIS proper?

    Why would he have to be an administrator? all the IIS Express files are owned by the user itself.

    I'm pretty sure the WebAdministration cmdlets are hard-wired to work with the full IIS only.

    If you want to use PowerShell with IIS Express you could still use the Microsoft.Web.Administration managed or COM objects, or even edit the XML directly. But using appcmd.exe would be much easier.

    Thursday, June 25, 2015 10:56 AM
  • User-1499466209 posted

    Really?

    I was pretty sure they don't.

    Since I'm pretty sure they do, we'll wait for an expert to settle this... :)

    I can be wrong, that happens really often!

    Why would he have to be an administrator?
    Just quoting the IIS Express FAQ (http://www.iis.net/learn/extensions/introduction-to-iis-express/iis-express-faq)

    Q: Does IIS Express require administrative privileges?
    A: The default IIS Express configuration allows users to run websites without administrative privileges. The setup program also installs a self-signed server certificate that enables standard users to run a site over SSL.
    
    Certain tasks do require elevated user rights. They include:
    
    Running a website on port 80 or another reserved port
    Installing a custom SSL certificate
    Running network-facing websites
    You must also have administrator user rights when using IIS Express on Windows Server 2003 SP2+.

    Thursday, June 25, 2015 11:22 AM
  • User-2058010767 posted

    I guess you don't have enough permissions to use Get-Website. Can you try with an admin account and/or in a PowerShell console run as administrator

    If I run under Administrator account I get different error Smile:

    PS C:\Windows\system32> Get-Website -Name "Default Web Site"
    format-default : Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
        + CategoryInfo          : NotSpecified: (:) [format-default], COMException
        + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.FormatDefaultCommand

    Thursday, June 25, 2015 2:44 PM
  • User-2058010767 posted

    If you want to use PowerShell with IIS Express you could still use the Microsoft.Web.Administration managed or COM objects, or even edit the XML directly. But using appcmd.exe would be much easier.

    The reason I don't like appcmd.exe is because I need not only to run the command, but interpret the results. For example, I need to check if VDIR exists before adding it. This can be done with appcmd.exe but I would need to parse out the command results which isn't fun.. I would much rather prefer cmdlet where everything is an object.

    Thursday, June 25, 2015 2:48 PM
  • User-1939905867 posted

    @stanb

    I totally hear you. I don't like using appcmd.exe at all. If you ever used the PowerShell cmdlets, you never want to go back.

    Here is a hack that may work for you:

    I still think the PowerShell cmdlets only work against the full IIS, so what you can try is copying your Express configuration to full IIS, change it with PowerShell and copy it back. 

    First install the proper IIS including the scripting tools.

    Before you want to make an IIS Express configuration change, run the following as admin:

    Move-Item $env:SystemRoot\System32\inetsrv\config\applicationhost.config -Destination $env:SystemRoot\System32\inetsrv\config\applicationhost.iis -Verbose
    Copy-Item $env:USERPROFILE\Documents\IISExpress\config\applicationhost.config -Destination $env:SystemRoot\System32\inetsrv\config\applicationhost.config -Verbose

    Now make your changes using the PowerShell cmdlets or even the IIS Manager, when done, move the file back:

    Move-Item $env:SystemRoot\System32\inetsrv\config\applicationhost.config -Destination $env:USERPROFILE\Documents\IISExpress\config\applicationhost.config -Force -Verbose
    Move-Item $env:SystemRoot\System32\inetsrv\config\applicationhost.iis -Destination $env:SystemRoot\System32\inetsrv\config\applicationhost.config -Verbose
    

    I only tested this quickly with IIS Express 8 on Server 2012 R2 but it seems to work.

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Thursday, June 25, 2015 5:38 PM
  • User-2058010767 posted

    I still think the PowerShell cmdlets only work against the full IIS, so what you can try is copying your Express configuration to full IIS, change it with PowerShell and copy it back. 

    Oh I see, one script to configure IIS (I need one for production anyway) and another script to copy configuration to IISExpress - nice!

    Friday, June 26, 2015 9:21 AM