Reputation: 493
I want to do some stuff with a Site and its Sub Applications (take them off line with app_offline.htm).
However I cannot find a way find or iterate through the virtual directories under a given site. I'm finding the site ok with
Get-ChildItem -Path IIS:\Sites | Where {$_.Name -match $siteName}
However I'm not sure how to drill down into it's child apps / virtual directories.
I was thinking something like this...
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
}
}
Any ideas?
Upvotes: 2
Views: 1576
Reputation: 493
Thanks Noah. I realised my mistake now. To answer my own question: Yes Get-VertualWebDirectory works, but NO it does not get Applicaitons under that site. I believe these "Sub sites" are only tired to the app pool and not the site. So I ended up just grabing the physical folders under that site.
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
}
Upvotes: 2