Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Add $computer to results of wmi-object results

$
0
0
Not sure if I need to put this in a new topic or not.  But in conjunction with task, i wanted to get a list of all servers and their current status of WinRM.  I was able to come up with this:

$computername = get-content "C:\temp\st\ServerListRM.txt"
 
$Query="select * from win32_service where name='WinRM'"
 
$ResultList = @()
 
foreach ($computer in $computername)
 
{
 
  write-host "Getting WinRM Service for " $computer
 
  $TempResult = Get-WmiObject -Query $query -computer $computer
 
  If ($TempResult -ne $null) {  
    
     $ResultList += $TempResult
 
  }
 
}
 
$ResultList| out-file "c:\temp\st\WinRM.txt"

I get the right results but I was hoping the Computer Name would be part of the WinRM.txt:

ExitCode  : 0
Name      : WinRM
ProcessId : 348
StartMode : Auto
State     : Running
Status    : OK

ExitCode  : 0
Name      : WinRM
ProcessId : 348
StartMode : Auto
State     : Running
Status    : OK

I've tried a couple of things but nothing is working.  I had added:

Get-WmiObject win32_computersystem | Select-Object -Property name

But I could not add it correctly.

Thoughts?

Jr. Admin

Jr. Admin


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>