I have a CSV file with 3 columns: Name, Job, And Directory.
I'm trying to Have the user type in Either a Name, or a Job, and it will return one or multiple lines output from column 3 (Directories)
$Profile = $PSScriptRoot + "\Profile.csv"
$Data = Import-Csv -Path $Profile
$JobChoice = Read-Host "Enter a Backup option"
$Results = $Data | Where-Object {( $_.Name, $_.Job ) -eq [string]$JobChoice}
$Results | Select-Object -ExpandProperty ($_.Directory)
The above example if I Type when prompted: "satisfactory" it will only show one return. but it shows all three columns i just need it to return the current lines directory.
Also, If I enter "SaveGame" as the Read-Host input. it will return all games with that job, but only the directories. I Would like to keep this feature as it accepts one game or multiple based on if i choose Name, or Job
I have even tried every combination of:
Select-Object -ExpandProperty ($_.Directory)
My goal of this is to add the data to the CSV then parse it and send them to xcopy to batch copy the returned directories.
Any help?
The CSV:
Name,Job,Directory
Satisfactory,Savegame,C:\Users\jrkid\AppData\Local\FactoryGame\Saved\SaveGames
TheLongDark,Savegame,C:\Users\jrkid\AppData\Local\Hinterland
TheInfected,Savegame,C:\Users\jrkid\AppData\Local\TheInfected
WrenchGame,Savegame,C:\Users\jrkid\AppData\Local\WrenchGame
Valheim,Savegame,C:\Users\jrkid\AppData\LocalLow\IronGate
RisingWorld,Savegame,C:\Users\jrkid\AppData\LocalLow\JIW-Games
7DTD,Savegame,C:\Users\jrkid\AppData\Roaming\7DaysToDie
You can use the following statement, which can be read as:
An object of
$csvwhere the value of the PropertyNameOR the value of the propertyJobare equal to$JobChoice. Then you can follow that statement with.Directoryto enumerate all values of theDirectoryproperty.See Member Enumerations for details.
Looking back at your code, the statement you're currently using would also work too, however
-inor-containswould be more efficient.The only issue with your code was the use of
($_.Directory), it should have been just: