Create website in IIS 7 - need help to create a folder from IIS Site IDRSS

7 replies

Last post Jan 29, 2014 12:15 PM by fab777

  • Create website in IIS 7 - need help to create a folder from IIS Site ID

    Oct 16, 2013 10:34 AM|r11tz5|LINK

    Hi I have a script already to create websites and application pools, but I am lacking knowledge to create a script that will create a folder that will get the IIS Site ID then create a folder in a directory. 

    siteID script iis folder powershell

  • Re: Create website in IIS 7 - need help to create a folder from IIS Site ID

    Oct 16, 2013 10:58 AM|fab777|LINK

    Hi,

    what do you want to do exactly? I'm not sure to understand.

    Do you want that the folder (on the filesystem) is named with the ID of the newly website?

    Anyway, I may be wrong, so here's a complete example of a PowerShell script that will create everything: Create-Website

    This message is provided "AS IS" with no warranties... But you can still mark it as answer if it's helped you.
    Fabrice ZERROUKI
    Wanna chill out? Here: JAHSound.net
  • Re: Create website in IIS 7 - need help to create a folder from IIS Site ID

    Oct 16, 2013 11:21 AM|r11tz5|LINK

    Hi, 

    When you run this powershell script: 

    get-website | select name,id,state,physicalpath,
    @{n="Bindings"; e= { ($_.bindings | select -expa collection) -join ';' }} ,
    @{n="LogFile";e={ $_.logfile | select -expa directory}},
    @{n="attributes"; e={($_.attributes | % { $_.name + "=" + $_.value }) -join ';' }} |
    Export-Csv -NoTypeInformation -Path C:\my_list.csv

    The results will show the IIS site "ID" which will be equal to a "value" example ID 2 - I need to get this Value when creating a site and have a folder created from it.

    So it would be Defaultsite = ID 1 - create a folder in directory C:\websites\ID2 ----- then i can link this using a Virtual Directory. 

  • Re: Create website in IIS 7 - need help to create a folder from IIS Site ID

    Oct 17, 2013 10:02 AM|fab777|LINK

    I'm really sorry but I still don't get it.

    What I understand is: you've already got some websites on your webserver. You want a script to create a new website. You want that 'to be created' website root folder located in a folder named 'C:\websites\ID_XX' where XX is an integer. You want that XX is "the higher existing website ID" +1

    Is that it?

    This message is provided "AS IS" with no warranties... But you can still mark it as answer if it's helped you.
    Fabrice ZERROUKI
    Wanna chill out? Here: JAHSound.net
  • Re: Create website in IIS 7 - need help to create a folder from IIS Site ID

    Oct 18, 2013 07:23 AM|r11tz5|LINK

    ok i will break down the process - 

    I want to create a site in IIS ----> this will generate site id -----> I now want to fetch the site id for the site created -----> and create a folder with that site id in a custom location.

    And in detail this would be: TemplateSite --> SiteID = "2" --> Create folder in C:\Websites\"2"

    I need a way of scripting this, main problem is fetching the SITEID  

  • Re: Create website in IIS 7 - need help to create a folder from IIS Site ID

    Oct 21, 2013 04:26 AM|fab777|LINK

    Ok, sorry to made you repeat yourself, I just wanted to be sure of what you wanna do.

    So to fetch the SiteId is pretty quick and easy, two lines:

    Import-Module WebAdministration
    Get-Website | Where-Object {$_.Name -match "TemplateSite"} | Select-Object -ExpandProperty ID

    So, for the complete process (and that's why I did not catch it on your fisrt post) you'll have to create your website with the New-Website cmdlet that requires to specify the PhysicalPath of your website. So at this point you don't know it. In your script you can use C:\Websites as PhysicalPath parameter, fetch the SiteId, create the corresponding folder and then move your website PhysicalPath in it.

    OR, there's a easier way to do it. Why not, choosing the ID of the website you'll create. Because, with the New-Website cmdlet, you can. There's an 'Id' parameter. So you can create your website:

    Import-Module WebAdministration
    New-Website -Name TemplateSite -Id 2 -Port 80 -IPAddress 123.123.123.123 -HostHeader www.templatesite.com -PhysicalPath 'C:\Websites\2' -ApplicationPool TemplateWebsite
    This message is provided "AS IS" with no warranties... But you can still mark it as answer if it's helped you.
    Fabrice ZERROUKI
    Wanna chill out? Here: JAHSound.net
  • Re: Create website in IIS 7 - need help to create a folder from IIS Site ID

    Oct 31, 2013 12:21 PM|r11tz5|LINK

    wow thanks for this sorry about the late reply i have been extremely busy... do you by any chance know much about iis 6 to iis 7.5 site migrations

  • Re: Create website in IIS 7 - need help to create a folder from IIS Site ID

    Jan 29, 2014 12:15 PM|fab777|LINK

    r11tz5

    do you by any chance know much about iis 6 to iis 7.5 site migrations
    I think your best friend for this kind of operations will be Web Deploy to migrate the website(s) configuration easily.

    Have a look: http://www.iis.net/learn/publish/using-web-deploy/migrate-a-web-site-from-iis-60-to-iis-7-or-above

    This message is provided "AS IS" with no warranties... But you can still mark it as answer if it's helped you.
    Fabrice ZERROUKI
    Wanna chill out? Here: JAHSound.net