Server name in output

Welcome Forums General PowerShell Q&A Server name in output

This topic contains 3 replies, has 4 voices, and was last updated by

 
Participant
1 year, 4 months ago.

  • Author
    Posts
  • #74797

    Participant
    Points: 0
    Rank: Member

    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

    Keymaster
    Points: 12
    Team Member
    Rank: Member

    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

    Keymaster
    Points: 1,624
    Helping HandTeam Member
    Rank: Community Hero

    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

    Participant
    Points: 160
    Helping Hand
    Rank: 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
    

The topic ‘Server name in output’ is closed to new replies.