簡體   English   中英

如何使用PowerShell和Web管理模塊檢查IIS中是否存在應用程序池?

[英]How to check whether an application pool exists or not in IIS using powershell and web administration module?

我使用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模塊。 導入后,您可以使用它。 請參閱我提到過的有關IIS驅動器的其他答案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM