Server name in output

Tagged: 

This topic contains 3 replies, has 4 voices, and was last updated by Profile photo of Rob Simmers Rob Simmers 2 weeks, 1 day ago.

  • Author
    Posts
  • #74797
    Profile photo of Venkata Kalyan
    Venkata Kalyan
    Participant

    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

  • #74808
    Profile photo of Will Anderson
    Will Anderson
    Keymaster

    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.

  • #74809
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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?

  • #74844
    Profile photo of Rob Simmers
    Rob Simmers
    Participant
    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
    

You must be logged in to reply to this topic.