I have a number of CSV files that are dumped to a directory (e.g., c:\admindump). Each file is named after a building ie., Baker.csv. I need to be able to go through each file and extract the name of the workstation (under the column heading of Name), the IP address (under column "Client IP Address), and the building it is located. The building is not contained in the CSV files but are gathered from the name of the file i.e., Baker.csv is Baker.
Using the code below, I am able to create my master list with the name of the computer and IP address but how do I get the building name into this master list?
$ListOFiles=Get-ChildItem -Path “c:\admindump” -File *.csv
$BigList=$ListOFiles|%{Import-CSV -Path "c:\admindump$"}
Function Get-Info {
Begin {}
Process {
$MachineInfo=new-object PSObject
$MachineInfo|Add-Member -type Noteproperty -Name WKSName -value $.name
$MachineInfo|Add-Member -type Noteproperty -Name IP -value $_.“Client IP Address”
Write-Output $MachineInfo
}
End {}
} #end function get-info
Something like that. Point being, you go through each file one at a time, rather than reading them in all at once, so that you’ll have each file’s filename available as you’re reading it’s data.