Can it be done as one liner

Welcome Forums General PowerShell Q&A Can it be done as one liner

Viewing 1 reply thread
  • Author
    Posts
    • #202046
      Participant
      Topics: 6
      Replies: 7
      Points: 115
      Rank: Participant

      IPs.txt

      10.10.30.45

      10.20.45.23

      get-wmiobject -computername (gc .\Ips.txt) -class win32_computersystem |select DNSHostname

      Is it possible to have output as follow just using one liner ( I can do it regular way)

      10.10.30.45     Desktop2

      10.20.45.23     Desktop3

      Thanks in advance

    • #202052
      Participant
      Topics: 2
      Replies: 1013
      Points: 2,078
      Helping Hand
      Rank: Community Hero

      Yes, just use a calculated property on the stuff you are passing in. Something like…

      Get-Content -Path 'FileUNC' | 
      ForEach {
          get-wmiobject -computername $PSItem -class win32_computersystem | 
          select @{
              Name = 'IPAddress'
              Expression = {$PSItem}
          }, DNSHostname
      }
      
      # Results
      IPAddress                                          DNSHostname
      ---------                                          -----------
      ...
      
Viewing 1 reply thread
  • You must be logged in to reply to this topic.