Powershell WebAdministration迭代给定IIS站点的应用程序/虚拟目录

时间:2014-09-16 02:20:46

标签: powershell iis

我想用网站及其子应用程序做一些事情(用app_offline.htm离线)。

但是我找不到找到或遍历给定站点下的虚拟目录的方法。我用

找到了网站
Get-ChildItem -Path IIS:\Sites | Where {$_.Name -match $siteName}

但是,我不确定如何深入了解它的子应用程序/虚拟目录。

我在想这样的事情......

Get-ChildItem -Path IIS:\Sites | Where {$_.Name -match $siteName} | `
ForEach{
    Write-Host $_.Name
    Get-WebVirtualDirectory -site $siteName | Foreach {
        Write-Host "Virtual Dir $_"
        #DO SOME STUFF
    }
}

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

谢谢诺亚。我现在意识到自己的错误。要回答我自己的问题:是的Get-VertualWebDirectory可以正常工作,但不会在该网站下获得Applicaitons。我相信这些“子网站”只对应用程序池而不是网站感到厌倦。所以我最终只是抓住该网站下的物理文件夹。

Write-Host "Taking Site [$siteName] [$state]" -ForegroundColor Cyan

$targets = @($siteName)
$site = Get-WebSite | Where { $_.Name -eq $siteName }

$apps = Get-ChildItem $site.PhysicalPath `
| Where-Object { $_ -in $appNames } `
| ForEach {
    $targets += "$siteName/$_"
}

$targets | ForEach{
    Change-App-Status -app $_ -state $state
}
相关问题