Change IIS Site Home Directory w/ Powershell

12,822

Solution 1

Ok, I tried this and it seems to work:

    $s.psbase.properties.path[0] = $siteConfig.path
    $s.psbase.CommitChanges()

Is there a better cleaner way of handling this?

Solution 2

Import-Module WebAdministration
Set-ItemProperty 'IIS:\Sites\Default Web Site\' -name physicalPath -value $siteConfig.path

http://technet.microsoft.com/en-us/library/ee909471(WS.10).aspx

Share:
12,822
vfilby
Author by

vfilby

I am a software engineer from Canada. I work in .Net and I use Mac's at home. I like to build things with wood I think G.I.R. is funny.

Updated on July 29, 2022

Comments

  • vfilby
    vfilby almost 2 years

    I can query the AD and find all the IIS sites and their virtual directories, now I need to be able to update those home directories and save the changes.

    After I fetch the directory entry I can display the site path using $site.Path, however setting it doesn't seem to have any effect. It never changes the actual stored path.

    I have tried $site.Path = <new path> and $site.Put( "Path", <new path> ) but neither have these seem to be affecting the stored path.

        $site = $iis.psbase.children | 
            where {$_.keyType -eq "iiswebserver"} | 
            where {$_.psbase.properties.servercomment -eq $siteConfig.name };
    
        $s = [ADSI]($site.psbase.path + "/ROOT");
        $s.Path
        # $s.Path = $siteConfig.path
        # $s.Put("Path", $siteConfig.path )
        $s.psbase.CommitChanges()