« Previous Next »

Thread: Help needed with script!

Last post 04-14-2009 11:32 AM by Bob Landau. 2 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (3 items)

Sort Posts:

  • 04-14-2009, 3:10 AM

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

    Help needed with script!

    Hello, I'm new in the programjming world and I have a script to create a site and application in IIS. This is it:

     

    Param
    ( [String] $Customername = $(Throw "You must enter a customer name"),
    [String] $Projectname = $(Throw "You must enter a project name"),
     [String]$Path="c:\inetpub\wwwroot",    #The Physical Path of the site
     [String]$AppPool="MyPool",  #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\sitemanager",  #The Applications Physical Path
     [String]$RelativePath="/sitemanager"  #The Applications Relative Path

    )

    [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, 8080)
    #$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()

     

     Now I want to add something to the script so that the site gets an ip address and a URL. So I want to have the parameters URL and IP. Is this possible to add? Can someone add this to my script? Thank you!

  • 04-14-2009, 5:24 AM In reply to

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

    Re: Help needed with script!

    Never mind, it's done.

     

    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, 8080)
    #$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()

    New-WebBinding -Name $Name -Port 80 -IPAddress $ip -HostHeader $hostheader

  • 04-14-2009, 11:32 AM In reply to

    Re: Help needed with script!

    fyi

     New-WebSite -Name Web1 -Id 2 -ApplicationPool AppPool1 -PhysicalPath c:\temp\web1 

     is an easier way to do what your up to.

    Having said that it is nice knowing what this cmdlet is up to. I've never bothered looking into the WebAdmin object model; now I'm curious

     bob

Page 1 of 1 (3 items)
Microsoft Communities