« Previous Next »

Thread: PowerShell IIS 6.0???

Last post 05-15-2009 1:04 AM by sergeia. 2 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (3 items)

Sort Posts:

  • 04-14-2009, 8:39 AM

    • Dazevo
    • Not Ranked
    • Joined on 04-06-2009, 9:35 AM
    • Posts 8

    PowerShell IIS 6.0???

    Is there anyway to edit this script to work with IIS 6.0 in Windows server 2003?

    This is my final script.

     

    Param
    ( [String] $Customername = $(Throw "You must enter a customer name"),
    [String] $Projectname = $(Throw "You must enter a project name"),
    [String]$Path="c:\inetpub\wwwroot\$Customername\$Projectname\website\wwwroot",    #The Physical Path of the site
     [String]$AppPool="DefaultAppPool",  #The name of the appPool the default app is part of
     [Int]$SiteID = $(Throw "You must enter a site id number"),
     [String]$PhysicalPath="c:\inetpub\wwwroot\$Customername\$Projectname\website\wwwroot",   #The Applications Physical Path
     [String]$RelativePath="/sitemanager",  #The Applications Relative Path
     [string]$ip = $(Throw "You must enter an ip"), 
     [string]$hostheader = $(Throw "You must enter an ip")
    )

    mkdir "C:\inetpub\wwwroot\$customername\$projectname\website\wwwroot"
    mkdir "C:\inetpub\wwwroot\$customername\$projectname\website\sitemanager"

    [String]$Name=("{0} {1}" -f $Customername,$ProjectName)


    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
    $iis = new-object Microsoft.Web.Administration.ServerManager
    $Site = $iis.Sites.Add($Name, $Path, 80)
    $Site.ServerAutoStart = $true
    $Site = $iis.Sites.CreateElement()
    $Site.ID = $SiteID
    $Site.Name = $Name
    $Site.Applications.Add("/", $Path)
    $Site.Applications["/"].ApplicationPoolName = $AppPool
    #$iis.Sites.Add($Site)
    $iis.CommitChanges()


    #Reference the Microsoft.Web.Administration namespace
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
    $iis = new-object Microsoft.Web.Administration.ServerManager

    #Add the Application to the site
    $iis.Sites[$Name].Applications.Add($RelativePath, $PhysicalPath)
    $iis.CommitChanges()
    Write-Host $AppPool
    #Add the application to the appPool
    $iis.Sites[$Name].Applications[$RelativePath].ApplicationPoolName = $AppPool
    $iis.CommitChanges()

     

    Thanks in advance.

  • 04-14-2009, 9:45 AM In reply to

    Re: PowerShell IIS 6.0???

    As fas as I know IIS PowerShell Snap-in does not work with IIS 6....

    Regards,
    MA Khan
    http://www.iisworkstation.com

    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • 05-15-2009, 1:04 AM In reply to

    • sergeia
    • Top 100 Contributor
    • Joined on 04-14-2008, 8:47 PM
    • Posts 68

    Re: PowerShell IIS 6.0???

    Well, this is not a Powershell snapin. It is Microsoft.Web.Administration library in use, which unfortunately doesn't work with IIS6 either. Both these tools are based on IIS7 configuration, and IIS6 configuration is quite different.

    I would recomment you to access IIS6 metabase from PowerShell using either old WMI provider ("Microsoftiisv2") or ADSI provider. Both are accessible from PowerShell. If you are suing it on IIS7 make sure you installed "IIS6 Management Compatibilty" components. In this case I would recommend to abandon IIS6 and switch to IIS7 APIs, you will have to do it sooner or later.

     

    --Sergei

Page 1 of 1 (3 items)
Microsoft Communities