“Normalizing” Output of an Inventory Function

Welcome Forums General PowerShell Q&A “Normalizing” Output of an Inventory Function

Viewing 7 reply threads
  • Author
    Posts
    • #236923
      Participant
      Topics: 6
      Replies: 16
      Points: 111
      Rank: Participant

      Hello friends, first time poster here ūüôā .

      I am trying to “normalize” the output of my function so it reads like:

      ComputerName Model MonitorModel MonitorSerial
      ABC123456 HP ZBook LG QHD 361343
      ABC123456 HP ZBook D3218HN X9R5K78200GE
      ABC123567 Surface Book TDM13056 94441728

      Like I’m joining a computer name table and a monitor table.

      However, it is currently outputting like this:

      ComputerName Model MonitorModel MonitorSerial
      ABC123456 HP ZBook D3218HN X9R5K78200GE
      ABC123567 Surface Book TDM13056  TDM1305694441728

      …Omitting the second monitor of the HP ZBook.

      Thanks! I’m sure I’m missing something obvious.

      • This topic was modified 3 months ago by tluizzi.
      • This topic was modified 3 months ago by tluizzi.
    • #236974
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      If you’re not interested in all monitors attached to a particular pc why are you collecting them anyway? And what criteria do you use to decide what monitor you want to omit? You could simply use the first one with:

      And of course you don’t need the loop to process the monitor list anymore. ūüėČ

    • #236977
      Participant
      Topics: 6
      Replies: 552
      Points: 2,090
      Helping Hand
      Rank: Community Hero

      What if you just run this against the two monitor HP? Powershell likes to combine output so if 2 objects have one monitor and 1 has 2… it will probably just not display it by default. Other test would be instead of write output do a | select * and confirm if that monitor is there, just not being shown when grouped.

    • #236986
      Participant
      Topics: 6
      Replies: 16
      Points: 111
      Rank: Participant

      Danke gentlemen,

      Toggling -Passthru on the internal foreach gets me close, but I still have dups.¬† Tried outputting with Sort-Object | Get-Unique but no effects.¬† Worst cause I can export to Excel and filter out unique rows, but I’d rather not do that.

      Latest Draft

      Output on my local HP machine: Two Monitors, 1x LG and 1x Dell

      One duplicate, the second “D3218HN”:

      Output on the remote Surface machine: No external monitors

      Only its own factory, internal monitor, but duplicated:

      Running Function with an array of the two machines

      Same results

      Thanks again for your help.

    • #236989
      Participant
      Topics: 6
      Replies: 552
      Points: 2,090
      Helping Hand
      Rank: Community Hero

      I’m reading on my phone, but your original code wouldn’t it just overwrite there first monitor with the second since it’s the same property name. Are you trying to collect them both in that single property?

    • #237001
      Participant
      Topics: 6
      Replies: 16
      Points: 111
      Rank: Participant

      That’s correct, Doug.¬† I would like the output like this:

      It would be like a SQL Inner Join between a Computer Table and a Monitor Table, one computer can have 1 or more monitors. Thanks!

    • #237007
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      I connot test at the moment but something like this should be enough actually:

    • #237016
      Participant
      Topics: 6
      Replies: 16
      Points: 111
      Rank: Participant

      Thank you Olaf! I’m seeing good results on my home computer – no duplicates.¬† Appreciate the help.

Viewing 7 reply threads
  • The topic ‘“Normalizing” Output of an Inventory Function’ is closed to new replies.