简体   繁体   English

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

[英]How to get all (IIS) websites status/state from remote machine using PowerShell?

I was trying to read the status of IIS website from remotely. 我试图从远程读取IIS网站的状态。 I tried below code. 我试过下面的代码。

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

But above command given me only Websites with https binding, when it comes to https it throws below error. 但是上面的命令只给了我带有https绑定的网站,当涉及到https时它会抛出错误。

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

I am trying to renmote a Windows Server 2008 R2 with IIS 7. Please guide me. 我正在尝试使用IIS 7升级Windows Server 2008 R2。请指导我。 Thanks ! 谢谢 !

Hope this will help for someone. 希望这对某人有所帮助。 Below is my findings and the answer. 以下是我的发现和答案。

Powershell sends only objects remotely, and render them using available templates. Powershell仅远程发送对象,并使用可用模板呈现它们。 So need to give a template accordingly. 所以需要相应地给出一个模板。 I used "Format-Table". 我用了“格式表”。 Be-careful, if you use "Format-Table" outside it results same error. 请注意,如果在其外使用“格式表”,则会产生相同的错误。 Remember to use it inside the scriptblock. 记得在scriptblock中使用它。

Error-prone: 容易出错:

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

Correct code: 正确的代码:

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

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

Good Luck ! 祝好运 !

There seems to be some problem with retrieving the objects using a remote session, but that is no blocking issue (I have run into this as well). 使用远程会话检索对象似乎存在一些问题,但这不是阻塞问题(我也遇到过此问题)。

To prevent the error from being written, you can use -ErrorAction like this: 要防止写入错误,可以使用-ErrorAction如下所示:

$Session = New-PSSession -ComputerName $serverName

$block = { 
    Import-Module 'webAdministration'
    Get-ChildItem -path IIS:\Sites
}

Invoke-Command -Session $Session -ErrorAction SilentlyContinue -ScriptBlock $block | 
    Out-File -append $WebreportPath

This way you will not see the remoting error, but you will still receive the data you need. 这样您就不会看到远程处理错误,但仍会收到所需的数据。

Note that this hides all errors, so you are possibly hiding an error that you may want to see. 请注意,这会隐藏所有错误,因此您可能隐藏了您可能想要查看的错误。 For that you will need a fix for the underlying ptoblem, so you can remove the -ErrorAction patch. 为此,您需要修复底层ptoblem,因此您可以删除-ErrorAction补丁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用Powershell从远程服务器获取IIS状态 - Unable to fetch IIS status from Remote server using Powershell 使用Powershell在远程计算机上重新启动IIS - Restart IIS on remote machine using Powershell 如何启动仅针对使用 Powershell 处于“已启动”状态的网站而停止的 IIS 应用程序池? - How to start IIS application pools which are stopped only for websites which has "Started" status using Powershell? 如何使用 Excel 工作表中的 powershell 从 Azure 获取虚拟机状态的特定列表 - How to get specifi list of Virtual Machine Status from Azure using powershell from Excel sheet 使用 powershell 从远程服务器获取服务状态 - Get service status from remote server using powershell 如何使用 powershell 在远程计算机上获取 Caps Lock 状态 - How to get Caps Lock status on remote computer using powershell 如何访问IIS:通过Powershell在远程计算机上驱动? - How to access IIS: drive on remote machine via Powershell? 如何使用PowerShell在IIS中停止和启动各个网站? - How can I stop and start individual websites in IIS using PowerShell? 如何使用Powershell在远程计算机上卸载服务? - How to uninstall a service on remote machine using powershell? Powershell命令导出远程服务器的IIS网站和应用程序池 - Powershell command to export IIS websites and app pools of a remote server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM