powershell scripts to attched apppool to existing site
$config = Get-Content Set-DefaultApplicationPoolConfig.xml
$defaultAppPoolName = $config.WebApplications.defaultAppPoolName
[Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration")
$service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
Write-Host "Checking presence default application pool $defaultAppPoolName..." -NoNewline
[Microsoft.SharePoint.Administration.SPApplicationPool] $newAppPool = $service.ApplicationPools[$defaultAppPoolName]
## The Default Application Pool MUST exist!
if($newAppPool -eq $NULL)
{
Write-Host ""
Write-Host -ForegroundColor Red "The default application pool '$defaultAppPoolName' does not exist."
Write-Host -ForegroundColor Red "Please ensure the application pool '$defaultAppPoolName' is already registered in SharePoint."
exit
}
else
{
Write-Host -ForegroundColor Green "[OK]"
}
foreach( $webAppConfig in $config.WebApplications.WebApplication )
{
$url = $webAppConfig.url
Write-Host "Updating $url..." -NoNewline
$webApp = Get-SPWebApplication $url -ErrorAction SilentlyContinue
if( $webApp -eq $null )
{
Write-Host -ForegroundColor Yellow " [Web application does not exist]"
continue
}
$currentAppPool = $webApp.ApplicationPool
if($currentAppPool.Name -eq $defaultAppPoolName)
{
Write-Host -ForegroundColor Green " [Change not needed]"
}
else
{
$webApp.ApplicationPool = $newAppPool
$webApp.Update()
$webApp.ProvisionGlobally()
Write-Host -ForegroundColor Green " [Done]"
}
}