我想对网站及其子应用程序执行一些操作(使用 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
}
}
有什么想法吗?
最佳答案
谢谢诺亚。我现在意识到了我的错误。回答我自己的问题:是的 Get-VertualWebDirectory 可以工作,但不,它不会在该站点下获取应用程序。我相信这些“子网站”只是对应用程序池感到厌倦,而不是对网站感到厌倦。所以我最终只是获取了该网站下的物理文件夹。
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
}
关于Powershell WebAdministration 迭代给定 IIS 站点的应用程序/虚拟目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25859742/