---------- 20191129 https://blog.darkthread.net/blog/get-iis-info-with-ps/ Get-Website Get-Website | Select -First 1 | ConvertTo-Json | Out-File "WebSiteModel.json" PS C:\WINDOWS\system32> Get-Website Name ID State Physical Path Bindings ---- -- ----- ------------- -------- Default Web Site 1 Started %SystemDrive%\inetpub\wwwroot http *:80: WebAPI 2 Started C:\Web\WebAPI http *:6856: WebGps 3 Started C:\Web\WebGps http *:8000: Get-Website | foreach { [String]::Format("{0,-24} {1}\\W3SVC{2}", $_.Name, $_.LogFile.Directory, $_.Id) } 【同場加映】如果要查 AppPool 的 ProcessId 呢? dir IIS:\AppPools 可列出所有 AppPool,dir IIS:\AppPools\AppPoolName\WorkerProcesses 則能查到指定 AppPool 的 PID: 我想讓資訊更精簡一點,用前面說的轉 JSON 技巧剖析資料物件的結構,得知 Process 資料放在 Collection 陣列: 用 where 篩選有包含 Process 項目的 Collection,印出 AppPool 名稱、PID、狀態: dir IIS:\AppPools | where { $_.WorkerProcesses.Collection.Length -gt 0 } | foreach { [String]::Format("{0,-16} {1,8} {2,8}", $_.Name, $_.WorkerProcesses.Collection[0].ProcessId, $_.WorkerProcesses.Collection[0].State) }