[英]test winrm connectivity on list of systems using powershell
I want to test whether or not winrm is running on a list of servers. 我想测试winrm是否在服务器列表上运行。
winrm id -r:servername works for individual systems but I want to test recursively for a list from a csv or text file. winrm id -r:servername适用于单个系统,但是我想递归测试csv或文本文件中的列表。
With output to a file saying "working" or "not working" for each. 输出到每个文件说“工作”或“不工作”的文件。
How do I do this? 我该怎么做呢?
Thanks all. 谢谢大家
Edit: 编辑:
Gotten to a point where I am passing a list of vm's and piping along until I get successful winrm connections output to a file and failures shown in the console. 到达要传递虚拟机和管道列表的地步,直到成功将winrm连接输出到文件,并在控制台中显示失败。
get-vm |where {$ .powerstate -like "PoweredOn"}|get-vmguest |where {$ .guestfamily -like "windowsGuest"}|foreach {winrm id -r:$_.hostname} |Out-File c:\\scripts\\winrmtest.txt get-vm |其中{$ .powerstate -like“ PoweredOn”} || get-vmguest |其中{$ .guestfamily -like“ windowsGuest”} | foreach {winid id -r:$ _。hostname} |输出文件c: \\脚本\\ winrmtest.txt
In my out-file I am getting output like IdentifyResponse ProtocolVersion = http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd ProductVendor = Microsoft Corporation ProductVersion = OS: 6.1.7601 SP: 1.0 Stack: 2.0 在我的外部文件中,我得到类似IdentifyResponse ProtocolVersion = http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd的输出。ProductVendor = Microsoft Corporation ProductVersion = OS:6.1.7601 SP:1.0堆栈:2.0
for successful connections and on the console I get the following for failures: 对于成功的连接,在控制台上,对于失败,我得到以下信息:
Error number: -2144108526 0x80338012 The client cannot connect to the destination specified in the request. 错误号:-2144108526 0x80338012客户端无法连接到请求中指定的目标。 Verify that the service on the destination is run ning and is accepting requests.
验证目标上的服务正在运行并且正在接受请求。 Consult the logs and documentation for the WS-Management service running on the destinat ion, most commonly IIS or WinRM.
请查阅有关在目的地(通常是IIS或WinRM)上运行的WS-Management服务的日志和文档。 If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".
如果目标是WinRM服务,请在目标上运行以下命令以分析和配置WinRM服务:“ winrm quickconfig”。 WSManFault Message = The client cannot connect to the destination specified in the request.
WSManFault消息=客户端无法连接到请求中指定的目标。 Verify that the service on the dest ination is running and is accepting requests.
验证目的地上的服务正在运行并且正在接受请求。 Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM.
有关在目标(通常是IIS或WinRM)上运行的WS-Management服务的信息,请查阅日志和文档。 If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".
如果目标是WinRM服务,请在目标上运行以下命令以分析和配置WinRM服务:“ winrm quickconfig”。
Need to get all the output into the file, along with the name of the guest vm the response is for. 需要将所有输出以及响应所针对的来宾vm的名称放入文件中。
Please keep in mind I have not used the VM cmdlets, however below is some code I think should help you. 请记住,我还没有使用过VM cmdlet,但是下面是一些我认为可以帮助您的代码。 I added a wmi to check the winrm service on each machine, if the service isn't running, look at the
startservice()
method for the win32_service
. 我添加了一个wmi来检查每台机器上的winrm服务,如果该服务未运行,请查看
win32_service
的startservice()
方法。 if this is unfamiliar to you, pipe | gm
如果您不熟悉,请使用
| gm
| gm
to see available properties and methods. | gm
查看可用的属性和方法。
However here are a few recommendations: 但是,这里有一些建议:
Exporting and managing data is easy and clean. 导出和管理数据既简单又干净。
"-Filter" vs "Where{}" “ -Filter”与“ Where {}”
Look into the VM cmdlets and see if they support -filter {property -operator "*filterby*"}
your code will run much faster. 查看VM cmdlet,看看它们是否支持
-filter {property -operator "*filterby*"}
您的代码将运行得更快。
$
All_VMS_Status = @() $
All_VMS_Status = @()
get-vm | where {$.powerstate -like "PoweredOn"} | get-vmguest | where {$.guestfamily -like "windowsGuest"} | foreach {
<# Create PowerShell Object with Hostname #>
$psobject = New-Object -TypeName psobject
$psobject | Add-Member -MemberType NoteProperty -Name "VM-HostName" -Value $($_.HostName)
<# Determin if WINRM is working #>
if(winrm id -r:$_.hostname) {
$Connection_Status = "Success"
} Else {
$Connection_Status = "Failed"
}
<# Check winrm service on remorte PC #>
$remote_winrm_Service = Get-WmiObject win32_service -ComputerName $($_.hostname) | Where{ $_.Name -eq "winrm"}
<# Add all information to PS object for exporting #>
$psobject | Add-Member -MemberType NoteProperty -Name "Winrm-Connection" -Value $Connection_Status
$psobject | Add-Member -MemberType NoteProperty -Name "winrm-state" -Value $($remote_winrm_Service.State)
$psobject | Add-Member -MemberType NoteProperty -Name "winrm-startmode" -Value $($remote_winrm_Service.StartMode)
$psobject | Add-Member -MemberType NoteProperty -Name "winrm-ExitCode" -Value $($remote_winrm_Service.ExitCode)
$psobject | Add-Member -MemberType NoteProperty -Name "winrm-Status" -Value $($remote_winrm_Service.Status)
$All_VMS_Status += $psobject
}
<# Export to csv #>
$All_VMS_Status | Export-Csv -Path "c:\scripts\winrmtest.csv" -NoTypeInformation`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.