We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

Change Site Settings [Answered]RSS

7 replies

Last post Mar 21, 2012 03:00 AM by wuwu

  • Change Site Settings

    Mar 16, 2012 09:24 AM|wuwu|LINK

    Hello,

    I want modify with powershell website settings, the physical path, bindings and the default document.

    For one Site, i know only this:

    Set-ItemProperty IIS:\Sites\DemoSite -name name -value NewDemoSite

    But how can i set the path, the default document and the path for more then one sites. I have 15 sites on my iis, and i want only change this three properties where the site name include "Europe".

    I hope somebody can help me,

    Horst

  • Re: Change Site Settings

    Mar 19, 2012 05:22 AM|fab777|LINK

    Hi,

    1. to find the websites with 'Europe' in the name:

    [code]$site = Get-Website | Where { $._name -like "*Europe*" }[/code] Maybe the '-contains' operator will be more accurate... You know better than me what sites you have, where and how the "Europe" string is placed in the name, etc.

    2. to modify the specified properties for these sites:

    foreach ($site in $sites) {

    Set-ItemProperty IIS:\Sites\DemoSite -name name -value NewDemoSite

    Set-ItemProperty IIS:\Sites\DemoSite -name physicalpath -value D:\Inetpub\wwwroot\NewDemoSite

    Set-ItemProperty IIS:\Sites\DemoSite -name bindings -value @{protocol="net.tcp";bindingInformation="80:new.demosite.com"}

    Set-ItemProperty IIS:\Sites\DemoSite -name defaultdoc -value @{value="new-index.html"}

    }
    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: Change Site Settings

    Mar 19, 2012 06:15 AM|wuwu|LINK

    Hello,

    i have tried this:

    cls
    Import-Module "WebAdministration" -ErrorAction Stop

    foreach($site in (dir iis:\sites\*Test*))

    {
    write-host $site.Name
    write-host $site.Bindings
    write-host $site.State
    write-host $site.physicalpath

    Set-ItemProperty IIS:\Sites\$site -name name -value NewDemoSite}

     But i get this error message:

    Test
    Started
    C:\inetpub\wwwroot\Test
    Set-ItemProperty : Cannot find path 'IIS:\Sites\Microsoft.IIs.PowerShell.Framework.ConfigurationElement' because it does not exist.
    At Config_IIS.ps1:13 char:17
    + Set-ItemProperty <<<<  IIS:\Sites\$site -name name -value NewDemoSite
        + CategoryInfo          : ObjectNotFound: (IIS:\Sites\Micr...gurationElement:String) [Set-ItemProperty], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetItemPropertyCommand

     I hope somebody can help me,

    Horst

  • Re: Change Site Settings

    Mar 19, 2012 06:29 AM|fab777|LINK

     Try Set-ItemProperty IIS:\Sites\$site.Name -name name -value NewDemoSite instead, it should do 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: Change Site Settings

    Mar 19, 2012 07:20 AM|wuwu|LINK

    Hello,

    it doesn't work :-( 

    cls
    Import-Module "WebAdministration" -ErrorAction Stop

    foreach($site in (dir iis:\sites\*Test*))

    {
    write-host $site
    write-host $site.Name
    # write-host $site.Bindings
    write-host $site.State
    write-host $site.physicalpath

    Set-ItemProperty IIS:\Sites\$site.Name -name Name -value NewDemoSite
    # Set-ItemProperty IIS:\Sites\DemoSite -name physicalpath -value D:\Inetpub\wwwroot\NewDemoSite
    # Set-ItemProperty IIS:\Sites\DemoSite -name bindings -value @{protocol="net.tcp";bindingInformation="80:new.demosite.com"}
    # Set-ItemProperty IIS:\Sites\DemoSite -name defaultdoc -value @{value="new-index.html"}
    }

    Error:

     Microsoft.IIs.PowerShell.Framework.ConfigurationElement
    Test2
    Started
    C:\inetpub\wwwroot\Test2
    Set-ItemProperty : Cannot find path 'IIS:\Sites\Microsoft.IIs.PowerShell.Framework.ConfigurationElement.Name' because it does not exist.
    At Config_IIS.ps1:14 char:17
    + Set-ItemProperty <<<<  IIS:\Sites\$site.Name -name Name -value NewDemoSite
        + CategoryInfo          : ObjectNotFound: (IIS:\Sites\Micr...ionElement.Name:String) [Set-ItemProperty], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetItemPropertyCommand

     Horst

  • Re: Change Site Settings

    Mar 20, 2012 05:21 AM|fab777|LINK

    Sorry mate, I'm currently working in a prehistorical company, with (in the best cases) W2K3/IIS6 and no powershell. So I have no way to test before posting here...

    To rename the website, the following command would maybe more appropriate:

    Rename-Item IIS:\Sites\$site.Name NewDemoSite


    But, actually, according to the error message you get, I think the problem isn't the command, but the variable...

    Does the "write-host $site.Name" returns the right value?

    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: Change Site Settings

    Mar 20, 2012 05:26 AM|wuwu|LINK

    Yes, if you see my command - script and the output including the error, the output from the variable is right, this is very strange!

    Thanks,

    Horst

  • Re: Change Site Settings

    Mar 21, 2012 03:00 AM|wuwu|LINK

    Hello,

     this is the Solution:

    Set-ItemProperty "IIS:\Sites\$($site.Name)" -name Name -value NewDemoSite

    I don't know why, but this works.

    Horst