ashwin_kumar525
asked on
Getting computer name in the out put
I run the command:
PS C:\temp> $computerlist = Get-Content .\complist.txt
PS C:\temp> Get-WmiObject win32_service -comp $computerlist | Where-Object { $_.name -eq "bits"} | ft
I get this:
ExitCode Name ProcessId StartMode State Status
-------- ---- --------- --------- ----- ------
1077 BITS 0 Manual Stopped OK
1077 BITS 0 Manual Stopped OK
1077 BITS 0 Manual Stopped OK
Well, how do I know which one's for which server in the server list I provided in the variable? is there a way tp get the computer name against each of those entries no matter what I chose to, list or table?
What I am expecting:
Name ExitCode Name ProcessId StartMode State Status
-------- -------- ---- --------- --------- ----- ------
Server1 1077 BITS 0 Manual Stopped OK
Server2 1077 BITS 0 Manual Stopped OK
Server3 1077 BITS 0 Manual Stopped OK
I hope this makes sense.
PS C:\temp> $computerlist = Get-Content .\complist.txt
PS C:\temp> Get-WmiObject win32_service -comp $computerlist | Where-Object { $_.name -eq "bits"} | ft
I get this:
ExitCode Name ProcessId StartMode State Status
-------- ---- --------- --------- ----- ------
1077 BITS 0 Manual Stopped OK
1077 BITS 0 Manual Stopped OK
1077 BITS 0 Manual Stopped OK
Well, how do I know which one's for which server in the server list I provided in the variable? is there a way tp get the computer name against each of those entries no matter what I chose to, list or table?
What I am expecting:
Name ExitCode Name ProcessId StartMode State Status
-------- -------- ---- --------- --------- ----- ------
Server1 1077 BITS 0 Manual Stopped OK
Server2 1077 BITS 0 Manual Stopped OK
Server3 1077 BITS 0 Manual Stopped OK
I hope this makes sense.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the response folks, each of those looks promising. let me try that tomorrow and let you know how it goes.
Add the computer name to the object you output.
$computerlist = Get-Content .\complist.txt
foreach ($computer in $computerlist)
{
Get-WmiObject win32_service -comp $computerlist | Where-Object { $_.name -eq "bits"} | Select @{Name="Computer";Expression={$computer}}, ProcessId, Startmode, State, Status #any other properties you want to return
}
$computerlist = Get-Content .\complist.txt
For each ($computer in $computerlist)
{
Write-Host $computer
Write-Host
Get-WmiObject win32_service -comp $computer | Where-Object { $_.name -eq "bits"} | ft
}