Hi after picking a few brains (again...) please about a query I have using PowerShell..
I have a CSV file which contains the following data
(spaced for ease of reading)
Its inside a function where I would like to be able to call and pass in a "day" name i.e. WED
i.e FilterCsv -Day "WED"
I then use
but I'd like to be able to do the following
to only select rows where ACTIVE = Y AND WED=Y (i.e REF001 & REF003)
however of course $Day is the dynamic fieldname I want to use (i.e. $_.WED = "Y" or SUN="Y" etc)
Ive tried creating a variablw with
but it doesnt filter when using this param
of course it works if I hardcode it as $_.WED="Y" and I know I can have lots of ifs/switches to pick based on the input/day name but I'd like to try and make it more efficient..
So my question is can I or how can I pass through the fieldname to the WHERE-OBJECT value..?
Sorry cant post more code but theres there potential of changing the CSV format if its easier..?
Thank you
PaulSc
I have a CSV file which contains the following data
Code:
REF, SUN,MON,TUE,WED,THU,FRI,SAT,ACTIVE
Ref001,N, Y, Y, Y, Y, Y, N, Y
REF002,Y, N, N, N, N, N, Y, Y
REF003,N, N, N, Y, N, N, Y, Y
Its inside a function where I would like to be able to call and pass in a "day" name i.e. WED
i.e FilterCsv -Day "WED"
I then use
Code:
importedcsv = import-csv - path "xxxx/yyyy.csv" | Where-Object ($_.ACTIVE -eq "Y")
but I'd like to be able to do the following
Code:
importedcsv = import-csv - path "xxxx/yyyy.csv" | Where-Object ($_.ACTIVE -eq "Y" -and [highlight #EF2929]$day[/highlight] -eq "Y")
however of course $Day is the dynamic fieldname I want to use (i.e. $_.WED = "Y" or SUN="Y" etc)
Ive tried creating a variablw with
Code:
new-variable -Name "Day" -value $Day -visibility Public
of course it works if I hardcode it as $_.WED="Y" and I know I can have lots of ifs/switches to pick based on the input/day name but I'd like to try and make it more efficient..
So my question is can I or how can I pass through the fieldname to the WHERE-OBJECT value..?
Sorry cant post more code but theres there potential of changing the CSV format if its easier..?
Thank you
PaulSc