Reputation: 2255
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".
I have retrieved the list on computer "B" using WMI (it has to be WMI because i want the start-up mode).
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.
Thanks
Upvotes: 0
Views: 539
Reputation: 52699
Just change $IssueService.name
to $IssueService
. There is no name
property in your string array. The item to the left of the -contains
operator needs to be a collection rather than a single item.
Upvotes: 3