gpt4 book ai didi

powershell - 如何使用PowerShell和Web管理模块检查IIS中是否存在应用程序池?

转载 作者:行者123 更新时间:2023-12-04 03:10:45 29 4
gpt4 key购买 nike

我正在使用 powershell 在我的 IIS 中自动配置网站。我有以下代码为我创建了一个 Web 应用程序池

#Creating a new Application Pool
New-WebAppPool "NewAppPool"

但在创建池之前, 我想检查池是否存在。我该怎么做?

请注意:我的系统上没有 IIS 驱动器。 因此,在路径中提到了 IIS 的命令如下 失败 :
$IISPath = "IIS:\AppPools"
cd $IISPath
if (Test-Path ".\NewAppPool") { Write-Host "NewAppPool exists." }

最佳答案

用这个:

import-module webadministration

$AppPoolName="NewAppPool"

if(Test-Path IIS:\AppPools\$AppPoolName)
{
"AppPool is already there"
return $true;
}
else
{
"AppPool is not present"
"Creating new AppPool"
New-WebAppPool "$AppPoolName" -Force
return $false;
}

注意:您需要 Powershell 的 WebAdministration 模块。导入后就可以使用了。见其他 ANSWER我在哪里提到过 IIS 驱动器

关于powershell - 如何使用PowerShell和Web管理模块检查IIS中是否存在应用程序池?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43246843/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com