Creating an IIS 6.0 Application Pool using Powershell

只愿长相守 提交于 2020-01-12 02:03:09

问题


How do I create an Application Pool on IIS 6.0 using a PowerShell script?

This is what I have come up with so far ...

$appPool = [wmiclass] "root\MicrosoftIISv2:IIsApplicationPool"

Thanks


回答1:


It isn't the most obvious process, but here is what worked for me..

$AppPoolSettings = [wmiclass]'root\MicrosoftIISv2:IISApplicationPoolSetting'
$NewPool = $AppPoolSettings.CreateInstance()
$NewPool.Name = 'W3SVC/AppPools/MyAppPool'
$Result = $NewPool.Put()

You might get an error with the call to Put(), but calling it a second (or third) time should make it work. This is due to an issue with PowerShell V1 and WMI.




回答2:


Thought I might share the script I came up with. Thanks to goes to Steven and leon.

# Settings
$newApplication = "MaxSys.Services"
$poolUserName = "BRISBANE\svcMaxSysTest"
$poolPassword = "ThisisforT3sting"

$newVDirName = "W3SVC/1/ROOT/" + $newApplication
$newVDirPath = "C:\" + $newApplication
$newPoolName = $newApplication + "Pool"

#Switch the Website to .NET 2.0
C:\windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -sn W3SVC/

# Create Application Pool
$appPoolSettings = [wmiclass] "root\MicrosoftIISv2:IISApplicationPoolSetting"
$newPool = $appPoolSettings.CreateInstance()
$newPool.Name = "W3SVC/AppPools/" + $newPoolName
$newPool.PeriodicRestartTime = 0
$newPool.IdleTimeout = 0
$newPool.MaxProcesses = 2
$newPool.WAMUsername = $poolUserName
$newPool.WAMUserPass = $poolPassword
$newPool.AppPoolIdentityType = 3
$newPool.Put()
# Do it again if it fails as there is a bug with Powershell/WMI
if (!$?) 
{
    $newPool.Put() 
}

# Create the virtual directory
mkdir $newVDirPath

$virtualDirSettings = [wmiclass] "root\MicrosoftIISv2:IIsWebVirtualDirSetting"
$newVDir = $virtualDirSettings.CreateInstance()
$newVDir.Name = $newVDirName
$newVDir.Path = $newVDirPath
$newVDir.EnableDefaultDoc = $False
$newVDir.Put()
# Do it a few times if it fails as there is a bug with Powershell/WMI
if (!$?) 
{
    $newVDir.Put() 
}

# Create the application on the virtual directory
$vdir = Get-WmiObject -namespace "root\MicrosoftIISv2" -class "IISWebVirtualDir" -filter "Name = '$newVDirName'"
$vdir.AppCreate3(2, $newPoolName)

# Updated the Friendly Name of the application
$newVDir.AppFriendlyName = $newApplication
$newVDir.Put()



回答3:


All is well! I modified the code so there is an explicit call to the $newPool.Put() command after the initial error. Thanks for your help!



来源:https://stackoverflow.com/questions/261237/creating-an-iis-6-0-application-pool-using-powershell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!