Merging two Arrays [Solved]

Author Message
lizaoreo

  • Total Posts : 13
  • Scores: 0
  • Reward points : 0
  • Joined: 1/31/2008
  • Location: Calhoun, GA
  • Status: offline
Merging two Arrays [Solved] Thursday, March 10, 2011 3:19 AM (permalink)
0
I've seen this mentioned in several threads by Googling, but haven't been able to replicate the results in the responses.  I'm sure it's not difficult, but it's driving me nuts and I'm not getting anywhere fast.  I'm querying a LANDesk server using SQL and pulling computers associated with a specific username.  Then I use the unique ID for the computer to query another table.  So I have two arrays with data.  Here's a sample of my output:

   
 Computer_IDN : 187   
 ServiceTag   : TAGNUMBER   
 BiosDate     : 08/03/2010   
 romVersion   : A08   
 SMBIOSver    : 2.5   
 Manufacturer : Dell Inc.   Computer_IDN : 13096   
 ServiceTag   : TAGNUMBER   
 BiosDate     : 04/03/2008   
 romVersion   : A05   
 SMBIOSver    : 2.4   
 Manufacturer : Dell Inc.   
 
 Computer_IDN  : 187   
 LoginName     : USERNAME DeviceName    : PC1 RecordDate    : 2/20/2010 10:42:03 PM   
 LastUpdInvSvr : 3/10/2011 10:06:40 AM   
 Laptop        : No   
 DeviceID      : {AFF080FE-7157-AC46-AB09-98CDC49464AF}   
 
 Computer_IDN  : 13096   
 LoginName     : USERNAME   
 DeviceName    : PC2   
 RecordDate    : 2/25/2011 7:52:11 AM   
 LastUpdInvSvr : 3/1/2011 9:27:31 AM   
 Laptop        : Yes   
 DeviceID      : {CD9276A4-F062-3F40-B3CB-EB2FC1D6CB9E} 


What I want is to combine those into groups for each computer, like so:
 Computer_IDN : 187   
 ServiceTag   : TAGNUMBER BiosDate     : 08/03/2010   
 romVersion   : A08   
 SMBIOSver    : 2.5   
 Manufacturer : Dell Inc. Computer_IDN  : 187   
 LoginName     : USERNAME   
 DeviceName    : PC1   
 RecordDate    : 2/20/2010 10:42:03 PM   
 LastUpdInvSvr : 3/10/2011 10:06:40 AM   
 Laptop        : No   
 DeviceID      : {AFF080FE-7157-AC46-AB09-98CDC49464AF} 

And my code:
 $username = (Read-Host)  
 $username = "`'$username`'"  
 $info = [Array](Invoke-SQLcmd2 -serverinstance 'SERVERNAME' -Database 'Landesk' -query "Select Computer_IDN, LoginName, DeviceName, RecordDate, LastUpdInvSvr, Laptop, DeviceID from Computer WHERE LoginName LIKE $($username)")  
 $size = 0..$($info.length - 1)  
 $info2 = $(foreach ($PC in $size) {[Array](Invoke-SQLcmd2 -serverinstance 'SERVERNAME' -Database 'Landesk' -query "Select Computer_IDN, ServiceTag, BiosDate, romVersion, SMBIOSver, Manufacturer from Bios WHERE Computer_IDN LIKE $($info[$PC].computer_idn.ToString())")})  
 
 $info  
 $info2 

<message edited by lizaoreo on Thursday, March 10, 2011 5:11 AM>
 
#1
    lizaoreo

    • Total Posts : 13
    • Scores: 0
    • Reward points : 0
    • Joined: 1/31/2008
    • Location: Calhoun, GA
    • Status: offline
    Re:Merging two Arrays Thursday, March 10, 2011 3:48 AM (permalink)
    0
    Trying something like this:
     $a=1,2,3 
     $b=4,5,6 
     
     $c=@() 
     for($i=0;$i -lt $a.count;$i++) 
     { 
     $c+="$($a[$i]),$($b[$i])" 
     } 
     
     $c 

    Gives me this:
    System.Data.DataRow,System.Data.DataRow
    System.Data.DataRow,System.Data.DataRow
    System.Data.DataRow,System.Data.DataRow
     
    #2
      lizaoreo

      • Total Posts : 13
      • Scores: 0
      • Reward points : 0
      • Joined: 1/31/2008
      • Location: Calhoun, GA
      • Status: offline
      Re:Merging two Arrays Thursday, March 10, 2011 5:10 AM (permalink)
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9