powershell - 如何使用 PowerShell 从远程计算机获取所有(IIS)网站状态/状态?

标签 powershell iis

我试图从远程读取 IIS 网站的状态。我试过下面的代码。

$Session = New-PSSession -ComputerName $serverName
$block = { 
import-module 'webAdministration'
Get-ChildItem -path IIS:\Sites
}
Invoke-Command -Session $Session -ScriptBlock $block  | Out-File -append $WebreportPath

但上面的命令只给了我带有 https 绑定(bind)的网站,当涉及到 https 时,它会抛出以下错误。

The data is invalid. (Exception from HRESULT: 0x8007000D)
+ CategoryInfo          : NotSpecified: (:) [Get-ChildItem], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.GetChildItemCommand

我正在尝试使用 IIS 7 远程远程处理 Windows Server 2008 R2。 请指导我。谢谢!

最佳答案

希望这对某人有所帮助。以下是我的发现和答案。

Powershell 仅远程发送对象,并使用可用模板渲染它们。 所以需要相应地给出一个模板。我使用了“格式表”。 请注意,如果您在外部使用“格式表”,则会导致相同的错误。记得在脚本 block 中使用它。

容易出错:

Invoke-Command  -ComputerName $serverName { Import-Module WebAdministration; Get-ChildItem -path IIS:\Sites} | Format-Table | Out-File -append $WebreportPath

正确代码:

Invoke-Command  -ComputerName $serverName { Import-Module WebAdministration; Get-ChildItem -path IIS:\Sites | Format-Table} | Out-File -append $WebreportPath

我指的是: http://forums.iis.net/t/1155059.aspx?IIS+provider+and+PowerShell+remoting

祝你好运!

关于powershell - 如何使用 PowerShell 从远程计算机获取所有(IIS)网站状态/状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29160597/

相关文章:

powershell - 方法调用失败,因为 [System.__ComObject] 不包含名为 'Click' 的方法

Azure 取消与删除订阅

powershell - 使用 PowerShell 同步文件夹

visual-studio - 如何向 VisualStudio 控制台添加命令?

java - 在 Windows 服务器上的 IIS 上部署 Java/JSP/Struts 2 Web 应用程序

asp.net-core - 在 IIS 中运行 Web 应用程序时,HttpContext 为 NULL

iis - 从 VM 访问 Azure 开发服务器?

powershell - 使用文本文件遍历PowerShell命令

asp.net-core - 如何判断自托管 ASP.NET Core 应用程序何时准备好接收请求?

javascript - 如果我重新启动应用程序池,客户端浏览器是否会引用我更新的 javascript 或 css 文件?