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

标签 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
    }
}

有什么想法吗?

最佳答案

谢谢诺亚。我现在意识到了我的错误。回答我自己的问题:是的 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/

相关文章:

使用 xPath .SelectSingleNode 的 Powershell 脚本无法从 web.config 文件 xmlns 中提取值

powershell - 为什么以及何时使用 32 位或 64 位 PowerShell 或 ISE?

git blame 使用 -L <n,m> 选项抛出一个错误的修订错误

jquery - 如何说服浏览器从缓存中加载图像而不是从服务器获取

iis - 如何运行 PowerShell 脚本 "in"IIS?

powershell - 激活交换PowerShell命令

powershell - 通过 PowerShell 设置 REG_NONE 值

ruby-on-rails - HttpPlatformHandler HTTP 错误 502.3 - 网关错误

c# - 重复类型错误?

iis - 间歇性 IIS/Azure 错误