简体   繁体   English

powershell:在数组中查找结果

[英]powershell: find results in an array

I've have a list of 10 windows services in an array from computer "A" and i want retrieve the same list in computer "B". 我在计算机“ A”的阵列中有10个Windows服务的列表,我想在计算机“ B”中检索相同的列表。

I have retrieved the list on computer "B" using WMI (it has to be WMI because i want the start-up mode). 我已经使用WMI检索了计算机“ B”上的列表(它必须是WMI,因为我想要启动模式)。

This is the code i used: 这是我使用的代码:

$IssueService = "Browser", "Dhcp", "Dnscache", "dwmrcs", "iphlpsvc", "LanmanServer", "LanmanWorkstation", "MMCSS", "MpsSvc", "Netlogon", "Netman", "netprofm", "NlaSvc", "nsi", "p2pimsvc","PNRPsvc","PolicyAgent", "SessionEnv", "stisvc", "W32Time", "WinHttpAutoProxySvc", "WinRM"
$Services = Get-WmiObject Win32_Service
$Services | Where-Object {$IssueService.name -contains $_.name}

Any help is appreciated, I'm new(ish) to PowerShell so a explanation would be greatly appreciated. 感谢您的任何帮助,我是PowerShell的新手,所以非常感谢您提供解释。

Thanks 谢谢

Just change $IssueService.name to $IssueService . 只要改变$IssueService.name$IssueService There is no name property in your string array. 您的字符串数组中没有name属性。 The item to the left of the -contains operator needs to be a collection rather than a single item. -contains运算符左侧的项目需要是集合,而不是单个项目。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM