<p>I'm trying to assign application pool to one web site in IIS7 using vb script:</p>

<pre><code>' Connect to the WMI WebAdministration namespace.'
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")

' Retrieve the application and display its Web site name and path.'
Set oApp = oWebAdmin.Get("Application.SiteName='Default Web Site',Path='/site'")

' Specify a new application pool name and save it.'
oApp.ApplicationPool = "NewAppPool"
oApp.Put_
</code></pre>

<p>the above script is not working!</p>

<p>Is there is a better way to assign application pool to web site under IIS (Using script)?</p>

Are you setting the app pool on a web site or a virtual directory?
i.e., "Default Web Site/site" (virtual directory) or just "Site" (web site).
If you trying to set it on a web site, not a virtual directory, you need to do something like:
```
```
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
Set oSite = oWebAdmin.Get("Site.Name='Site'")
oSite.ApplicationDefaults.ApplicationPool = "NewAppPool"
oSite.Put_
```
```