I have a CSV file with data like this..
Data.csv
Name, Machine, Model, Wifi
User1, Machine1, Dell Lattitude, Connected
User2, Machine2, Dell Lattitude, disconnected
User3, Machine3, Dell Lattitude, Connected
I also have txt file with specific machines like this
desktops.txt
machine1
machine4
machine5
What i need to do is change the "WIFI" value from "connected' to "connected*" if the machine has a value of "connected" and its also in the desktops.txt file
Here is the code i have, but its not changing the WIFI value on any rows.
$ImportedCSV = Import-CSV data.csv
foreach($server in Get-Content .\desktops.txt) {
$NewCSV = Foreach ($Entry in $ImportedCsv) {
$SEL = Select-String -Path desktops.txt -Pattern "$server"
if (($SEL -eq $True) -and ($Entry.WIFI -eq 'connected')) {
$Entry.WIFI = 'connected*'
}
$Entry
}
}
$NewCSV | Export-CSV data2.csv -NoTypeInformation
Desired CSV output is
Name, Machine, Model, Wifi
User1, Machine1, Dell Lattitude, Connected*
User2, Machine2, Dell Lattitude, disconnected
User3, Machine3, Dell Lattitude, Connected
thank you