Hi Reddit
I have a directory structure that looks similar to this:
C:carsfordfiesta
C:carsfordfocus
C:carsbmw118i
C:carsvwgolf
C:carsvwpolo
In each of the car model folders are reports generated daily and they have todays date in the filename. When I do loop through the reports I want to get the car model and put it as a field in my PSObject. How do I do this? Here is my code:
$carlist = New-Object System.Collections.ArrayList $currentdate = Get-Date "yyyyMMdd" $cardirectory = "C:cars***$currentdate*.csv" Function CreateCars { Foreach($file in dir $cardirectory) { $car = new-object -TypeName PSObject $car| add-member -Membertype NoteProperty -Name CarModel -Value <put something here to get polo/golf/fiesta/118i> $car| add-member -Membertype NoteProperty -Name CarBrand -Value <put something here to get vw/ford/bmw> $car| add-member -Membertype NoteProperty -Name file -Value $file.Name $carList.Add($car) >> null } }
When I do the add-member what do I put after the -value?
submitted by /u/Finch11
[link] [comments]
The post How do I get the actual directory path when looping through a directory variable with * in it? appeared first on How to Code .NET.