如何使用 PowerShell 獲取 IIS 應用程式池名稱?


若要使用 PowerShell 獲取 IIS 應用程式池名稱,你需要使用 IIS PSDrive,但為此,我們在執行命令的伺服器上需要 IIS PowerShell 模組 WebAdministration 或 IISAdministration。

如果 WebAdministration 模組已經安裝,則使用下面的命令匯入此模組。

Import-Module WebAdministration -Verbose

一旦匯入上面的模組,你就可以在當前會話中看到 IIS PSDrive 將被啟用。

若要獲取所有應用程式池,請執行下面的命令,

Get-ChildItem IIS:\AppPools\

輸出

Name                     State        Applications
----                     -----        ------------
.NET v2.0                Started
.NET v2.0 Classic        Started
.NET v4.5                Started
.NET v4.5 Classic        Started
Classic .NET AppPool     Started
DefaultAppPool           Started      Default Web Site

若要檢索特定應用程式池名稱,請使用 Get-Item 命令,

Get-Item IIS:\AppPools\DefaultAppPool

輸出

Name                     State        Applications
----                     -----        ------------
DefaultAppPool           Started      Default Web Site

另一種簡單的方法是使用 IISAdministration 模組的 Get-IISAppPool 命令。

Import-Module IISAdministration -Verbose

使用 Get-IISAppPool 命令。

Name                 Status       CLR Ver  Pipeline Mode  Start Mode
----                 ------       -------  -------------  ----------
DefaultAppPool       Started      v4.0     Integrated     OnDemand
Classic .NET AppPool Started      v2.0     Classic        OnDemand
.NET v2.0 Classic    Started      v2.0     Classic        OnDemand
.NET v2.0            Started      v2.0     Integrated     OnDemand
.NET v4.5 Classic    Started      v4.0     Classic        OnDemand
.NET v4.5            Started      v4.0     Integrated     OnDemand

對於特定的應用程式池,使用 -Name 屬性,

Get-IISAppPool -Name DefaultAppPool

更新於: 28-Apr-2021

6 千次以上的瀏覽量

開啟你的職業生涯

完成該課程獲得認證

開始
廣告