Solved

Getting computer name in the out put

Posted on 2013-02-04
5
390 Views
Last Modified: 2013-02-06
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.
0
Comment
Question by:ashwin_kumar525
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Expert Comment

by:unsatiated
ID: 38851995
Something along the lines of this:  I normally use xml as my source to iterate over, but you can do something like the below.  Pipe the computer list into variable.  perform a for-each on the items.

$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
     }
0
 
LVL 84

Accepted Solution

by:
oBdA earned 300 total points
ID: 38852010
For example like this (and replace the properties for "select" with the properties you want in the required order):
Get-WmiObject win32_service -ComputerName $ComputerList -Filter "Name='Bits'" | Select Systemname,Status,State,StartMode | ft

Open in new window

0
 
LVL 40

Assisted Solution

by:footech
footech earned 200 total points
ID: 38852105
One other method I'll mention.  If you were using PSRemoting, each returned object would include the name of the computer it was returned from.
PS C:\test\PS> invoke-command -computername $computerlist {Get-WmiObject win32_service -Filter "Name='Bits'"} | ft

         ExitCode Name                    ProcessId StartMode        State            Status           PSComputerName
         -------- ----                    --------- ---------        -----            ------           --------------
                0 BITS                          912 Manual           Running          OK               wkstn1

Open in new window

0
 
LVL 10

Author Comment

by:ashwin_kumar525
ID: 38852298
Thanks for the response folks, each of those looks promising. let me try that tomorrow and let you know how it goes.
0
 
LVL 17

Expert Comment

by:Learnctx
ID: 38852813
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
}

Open in new window

0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question