Author Posts

July 12, 2017 at 5:17 pm

Hi,
I trying to get service which running with specific account on remote servers. I am able to achieve it, but in output, I am not able to get the server name.

import-csv test.csv | foreach {

Get-WmiObject -Class Win32_Service -ComputerName $_.computer | where {$_.StartName -eq 'domain\user'} | select Server, Name, DisplayName, StartName

} | Export-Csv C:\Users\test\Desktop\Test\Search_String\result.csv -NoType

Can someone guide me, what I am missing?

-Kalyan

July 12, 2017 at 5:48 pm

Hey there Venkata. Server is not a property output by that command. Try running SELECT -first 1 -property * and see what fits best. PSComputerName is usually a good one to use.

July 12, 2017 at 6:02 pm

Well, because you're working with what's emitted by Get-WmiObject, you need to have what you need already there, or attach it.

Have you seen if PowerShell is adding a PSComputerName property to the output of Get-WmiObject?

July 13, 2017 at 1:52 am

import-csv test.csv | foreach {

Get-WmiObject -Class Win32_Service -ComputerName $_.computer | 
where {$_.StartName -eq 'domain\user'} | 
select PSComputerName, #possible automatic variable filled with computername
       @{Name="Server";Expression={$_.computer}}, #manually populate name with calculated property
       Name, 
       DisplayName, 
       StartName

} | Export-Csv C:\Users\test\Desktop\Test\Search_String\result.csv -NoType