Powershell script to search a CSV file for numbers in a Column

Hi All

I am working on a project in Powershell to show the output of various share drives in HTML

I need to find a way to search Column 2 for various values from 0 to 2048 and add the following after each one depending on the value.

0-99 Red
100-199 Amber
200-2048 Green

Example below

Column 1      Column 2      Column 3      Column 4
Unc Path_1      18      sharename_1      2048
Unc Path_2      98      sharename_2      2048
Unc Path_3      12      sharename_3      2048
Unc Path_4      18      sharename_4      2048
Unc Path_5      4      sharename_5      2048
Unc Path_6      41      sharename_6      2048
Unc Path_7      72      sharename_7      2048
Unc Path_8      12      sharename_8      2048

Thank you for looking and hopefully you can help me.

Si WaltonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Assuming we're talking about a real csv file here; your example above would look like this:
"Column 1","Column 2","Column 3","Column 4"
"Unc Path_1","18","sharename_1","2048"
"Unc Path_2","98","sharename_2","2048"
"Unc Path_3","12","sharename_3","2048"
"Unc Path_4","18","sharename_4","2048"
"Unc Path_5","4","sharename_5","2048"
"Unc Path_6","41","sharename_6","2048"
"Unc Path_7","72","sharename_7","2048"
"Unc Path_8","12","sharename_8","2048"

Open in new window

One-liner for copy and paste into a shell (pipe the output to Export-Csv -NoTypeInformation C:\Temp\export.csv or whatever as required):
Import-Csv "C:\Temp\test.csv" | Select-Object -Property *, @{Name="Column 5"; Expression={Switch ([int]$_."Column 2") {{$_ -in 0..99} {"Red"}; {$_ -in 100..199} {"Amber"}; default {"Green"}}}}

Open in new window

Import-Csv "C:\Temp\test.csv" | Select-Object -Property *, `
	@{Name="Column 5"; Expression={
		Switch ([int]$_."Column 2") {
			{$_ -in 0..99} {"Red"}
			{$_ -in 100..199} {"Amber"}
			default {"Green"}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Si WaltonAuthor Commented:
Thank you oDba

Thats works a treat

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.