Hello all and best wishes for 2022!
I have the following CSV file:
Name,EmployeeID,File
JohnDoechebox,0009001,ImageBig1.png
JohnDoechebox,0009001,ImageBig2.png
JohnDoechebox,0009001,ImageFlat1.jpg
JohnDoechebox,0009001,ImageFlat2.jpg
JaneJefferson,0009006,IntDoc.docx
JaneJefferson,0009006,IntDoc2.docx
JaneJefferson,0009006,IntImage.jpg
JaneJefferson,0009006,ExtImage.jpg
I want to import the CSV file, this I can do with Import-CSV. Then I want to foreach the imported CSV file so that all rows get parsed.
I have been testing a bit and I came up with the following:
$Name = @()
$EmployeeID = @()
# Importing the CSV file and fill the array
Import-Csv -Path "C:\Temp\TestNew.csv" |`
ForEach-Object {
$Name += $_."Name"
$EmployeeID += $_."EmployeeID"
Write-Host "Your name is $($_.Name) and your Employee ID is $($_.EmployeeID)"
}
This works as expected. So now I want to build it so that I can get all the files for that specific user based on the EmployeeID (because names can be duplicate, EmployeeID is always unique) and output the files by Write-Host. Like this:
Write-Host "Your name is $($_.Name) and your Employee ID is $($_.EmployeeID)" You have the following files:
Later I also want to execute an action with each file to copy it somewhere.
Any help would be greatly apreciated! Thanks in advance!
$($User.Name)outputs the EmployeeID? I have made some changes to also create a folder based on the "Name" column and copy the files of the user (by using the EmployeeID) to that specific folder.