0

I am trying to output computer manufacture dates by way of looking up a csv file with a list of processor dates and returning the Dates if processor date of computer matches what is populated in the csv list. I am trying to achieve this by using the import-csv cmdlet which will import a csv file from an excel sheet with prepopulated processor models and their Date objects. A sample of this CSV File is posted below. A powershell script which contains this command will then look up and compare based on header rows and then will provide the right date based on match or if condition met true.

My code so far returns all release Dates instead of matched Date. Which isnt the expected result.

Here is a sample of my script

$OutModel = Get-WmiObject Win32_Processor | Select name

Import-Csv C:\date_source\manufacture_date.CSV -Delimiter ";"  | where {$_.Name -ne ""} | %{write-host The Manufacture Date is: $_.Release}

Here is a sample of my import-Csv File

Model;Release;;;;;;;;

;;;;;;;;;

i7-8086K ;Q2 2018;;;;;;;;

i7-8700K;Q4 2017;;;;;;;;

i7-8700;Q4 2017;;;;;;;;

i5-8600K;Q4 2017;;;;;;;;

i5-8500;Q2 2018;;;;;;;;

i5-8400;Q4 2017;;;;;;;;

i3-8350K;Q4 2017;;;;;;;;

i3-8100;Q4 2017;;;;;;;;

Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz;Q3 2017;;;;;;;;

i7-8550U;Q3 2017;;;;;;;;

i7-8750H;Q2 2018;;;;;;;;

i5-8350U;Q3 2017;;;;;;;;

i5-8300H;Q2 2018;;;;;;;;

i5-8250U;Q3 2017;;;;;;;;

i7-8665U;Q2 2019;;;;;;;;

i7-8565U;Q3 2018;;;;;;;;

i5-8365U;Q2 2019;;;;;;;;

i5-8265U;Q3 2018;;;;;;;;

i3-8145U;Q3 2018;;;;;;;;

I am expecting something like "The Manufacture Date is : Q2 2018" ..one line . Some code snippets or code ideas to get the exact to get expected output will be appreciated.

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
john zuh
  • 59
  • 1
  • 11

2 Answers2

1

here's a slightly different way to do it. [grin] it uses a lookup table to make things more obvious - and just a tad faster than using a filter.

# fake reading in a CSV file
#    in real life, use Import-CSV
$CPU_Data = @'
Model;ReleaseDate
i7-8086K;Q2 2018
i7-8700K;Q4 2017
i7-8700;Q4 2017
i5-8600K;Q4 2017
i5-8500;Q2 2018
i5-8400;Q4 2017
i3-8350K;Q4 2017
i3-8100;Q4 2017
Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz;Q3 2017
i7-8550U;Q3 2017
i7-8750H;Q2 2018
i5-8350U;Q3 2017
AMD Phenom(tm) II X4 945 Processor;Q4 2009
'@ | ConvertFrom-Csv -Delimiter ';'

# build a lookup table
$CPU_ReleaseDateLookup = [hashtable]::new()
foreach ($CD_Item in $CPU_Data)
    {
    $CPU_ReleaseDateLookup.Add($CD_Item.Model, $CD_Item.ReleaseDate)
    }

# the CIM cmdlets are a tad faster than the WMI cmdlets - and are not deprecated
$CPU_Name = (Get-CimInstance -ClassName CIM_Processor).Name


'The release date for [ {0} ] is [ {1} ].' -f $CPU_Name, $CPU_ReleaseDateLookup[$CPU_Name]

output ...

The release date for [ AMD Phenom(tm) II X4 945 Processor ] is [ Q4 2009 ].
Lee_Dailey
  • 7,292
  • 2
  • 22
  • 26
  • Tested and works as expected. I noticed one thing after populating my CSV that i had to copy the exact CPU name as it is on my computer before it could be read properly and the downside about this is since i dont everyone's computer with me to be checking @ what ghz of speed they have like in my case @ 1.9 ghz is there a way i could look up just by picking out the important strings eg i7-8086K from processor name and then ignoring then stripping out the rest as match? . Refer to content below.. – john zuh Jul 11 '19 at 22:05
  • I am also thinking of an else condition in case the hardware doesnt find a match in the hashtable. Otherwise i will have to make do with this for now. – john zuh Jul 11 '19 at 22:13
  • Will be good if i could match with this format it is on the intel website -> . Intel(R) Core(TM) i7-8086K Processor;Q2 2018 or for this which is identical to what i have on my computer -> . Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz . ;Q3 2017 I could Match this i7-8660U and strip out (ignore) the rest ;Q2 2019 – john zuh Jul 11 '19 at 22:25
  • @johnzuh - there are only a few ways to match up the text as it exists in the CIM/WMI call and the lookup table. i used the whole thing as returned by my CIM call. you could do a call to the Intel site, build a table from that, and use `$Keys -match $CPU_Info` to get the key to use in the hashtable call. you may want to simply build the CIM CPU name info into a table and have a low level tech manually enter the release date info. [*grin*] it's mostly a do-it-once situation and may simply be faster to do it by hand. [*sigh ...*] – Lee_Dailey Jul 11 '19 at 23:05
  • # I did Split the string on " " (space) which removes all characters before , after spaces and just took the [2] element to return just the specific Model e.g . $CPU_Model = $CPU_Name.Split(" ")[2] returns i7-8650U which i then match with the corresponding date in my table. Kinda improvises what i want to achieve here so i dont have to match the whole Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz which was returned by the CIM. Appreciate – john zuh Jul 15 '19 at 06:45
  • ah! that makes sense ... as long as the names are consistent. here's hoping they stay that way ... [*grin*] – Lee_Dailey Jul 15 '19 at 07:04
0

Running the below would easily get you your desired result. Not the best way to do it but certainly a way.

$models = import-csv C:\temp\modeltest.csv -Delimiter ";" 
$CPU = $(((Get-WmiObject Win32_Processor | Select name) -split ' ')[2])
Write-Host "The Manufacture Date is : $(($models.Where({$_.Model -eq "$CPU"})).Release)"
Drew
  • 3,814
  • 2
  • 9
  • 28