如何在 Powershell 上使用 WMI 读取 IIS 设置?

How to use WMI on Powershell to read IIS settings?

我是 wmi、powershell、IIS 和英语的初学者。

通常,我使用 get-wmiobject 作为 powershell 上的示例代码。
目标:WindowsServer 2012、IIS8
Powershell 运行 客户端:Windows7ProSP1x64、Powershell v5、.NET 4.6.1

Get-WmiObject -Query "Select * from Win32_QuickFixEngineering" `
  -Namespace root/cimv2 -ComputerName $hostname -Credential $cred

但是在 IIS 的情况下,我不知道如何使用那个命令行开关。

是否收集了任何名称空间?如何在 Powershell 上将搜索类名用于 IIS?

您不必使用 WMI(我认为这对 IIS 没有意义,但请不要引用我的话)。您可以使用 webadministration 模块:

Import-Module WebAdministration
Get-ChildItem –Path IIS:\AppPools
New-Item –Path IIS:\AppPools\MyAppPool
Get-ItemProperty IIS:\AppPools\MyAppPool | select *
Set-ItemProperty -Path IIS:\AppPools\MyAppPool -Name managedRuntimeVersion -Value 'v4.0'
Remove-WebAppPool -Name MyAppPool

或者您可以使用模块中的各种 cmdlet 来管理 IIS