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
    • #202046
      Topics: 6
      Replies: 7
      Points: 115
      Rank: Participant


      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)     Desktop2     Desktop3

      Thanks in advance

    • #202052
      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.