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>