Reputation: 991
I’m trying to do a simple thing of listing a computername in an output from a foreach loop, but I just can’t seem to get it working, was hoping someone could point me in the right direction..
I’ve tried the below
$computers = (Get-AdComputer -Filter "name -like ‘vm-*'").Name | Sort-Object
foreach ($computer in $Computers)
{
Get-Service -Name RpcSs | Select Name, Status, computername
}
Thanks
Upvotes: 0
Views: 3730
Reputation: 2434
you need to use the $computer in the get-servie cmdlet. In your code you will always get the services of the local computer.
Try like this:
$computers = (Get-AdComputer -Filter "name -like ‘vm-*'").Name
foreach ($Computer in $Computers)
{
Get-Service -Name RpcSs -ComputerName $Computer| Select-Object -Property Name, Status, MachineName
}
Upvotes: 3