How would I go about obtaining the value of a secondary field in a CSV, while foreaching results in another CSV?
Ex: List of computers, then search for serial in list, then get response.
CSV1 has list of computer names, serials ,and vendor IDs.
CSV2 has list of vendor IDS, and responsible party
Sample code:
$systems = import-csv -path "K:\systems.csv"
$vendors = import-csv -path "K:\vendors.csv"
$vendortable= @{}
$vendors | ForEach-Object {
$vendortable[$_.vendorid] = New-Object -Type PSCustomObject -Property @{
'ID' = $_.vendorid
'Managed' = $_.Managed
}
}
Foreach ($computer in $systems){
$host = $system.Host
if ($vendortable.key -match $system.vendorid){
$xvendor = $vendortable.Managed
}
$vendorobj = New-Object PSObject -property @{
'Host'=$System.host
'Mgr=$xvendor
}
$vendorobj |Select-object "Host","Mgr" |Export /////////
This returns an object of All values System.Object[] in the vendor table, not just one.
CSV1
Host,Serial,VendorID
A15,gtjk123,9001
C15,gtjk456,6402
T15,gtjk678,2301
S15,gtjk103,0101
CSV2
VendorID,Managed
9001,Trancom
6402,Stratus
2301,Psycorp
0101,Dell