Change IIS Site Home Directory w/ Powershell

旧时模样 提交于 2021-02-07 02:09:56

问题


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()

回答1:


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




回答2:


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?



来源:https://stackoverflow.com/questions/299546/change-iis-site-home-directory-w-powershell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!