代码之家  ›  专栏  ›  技术社区  ›  Robert Wagner

使用Powershell创建IIS 6.0应用程序池

  •  6
  • Robert Wagner  · 技术社区  · 16 年前

    这就是我到目前为止想到的。。。

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

    谢谢

    3 回复  |  直到 13 年前
        1
  •  7
  •   Robert Wagner    16 年前

    我想我可以和大家分享我的剧本。感谢史蒂文和莱昂。

    # 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()
    
        2
  •  6
  •   Steven Murawski    16 年前

    这不是最明显的过程,但以下是对我有效的方法。。

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

    对Put()的调用可能会出错,但第二次(或第三次)调用应该可以使其正常工作。这是因为PowerShell V1和WMI存在问题。

        3
  •  0
  •   Ferd Biffle Ferd Biffle    16 年前

    一切都很好!我修改了代码,以便在初始错误后显式调用$newPool.Put()命令。谢谢你的帮助!