I have a directory where admins are dumping files pertaining to workstations located at each building. Within each CSV file, I would like to extract two columns (Header Client IP Address and Name). Each CSV file is named after a building e.g, Tomlinson.csv. I would also like to place the name of the file (really the name of the file minus the ".csv" suffix which is the name of the building) into the custom object I am creating. The last part is what I am looking for help on. How do I add members to the custom object pertaining to the information from the csv file plus name of the building?
Here is the road I was heading down
So, I get the list of files by
$ListOFiles=Get-ChildItem -Path c:\admindumps -File *.csv
#Note: Each csv is named after a building, e.g., Tomlinson.csv
I can then import the relevant information (with the exception of the Building which comes from the file name of the csv) by
$MasterListOWorkstations=$ListOFiles|%{Import-CSV -Path c:\admindumps\$_"}
Each CSV has too much information, I only need two columns so I create a custom psobject
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
$MasterLIstOWorkstations|Get-Info
The last command gives me the information I am looking for but how would I add building name to it?
↧