I have a bunch of CSV files containing information about DHCP scopes (100+ files, one for each server). I wish to merge the data from all into a new table. There are ways to merge the CSVs but that's not good enough, because one the most important piece of information is not included inside the individual CSV files...that of the server name. The server name is coming from the filename itself. Hence the approach to build a new table.
My issue is that the properties for SubnetMask, StartRange, EndRange, ScopeID and State are being output in the same "cell". I managed to do it for the ScopeName (i.e. managed to get one ScopeName per line), but not sure how to approach the rest.
$outputTable = $null
$files = Get-ChildItem -Path "C:\Temp\Discovery\" -Filter *Scopes.csv
Write-Host $files
ForEach($file in $files)
{
$scopeFile = Import-Csv $file
ForEach ($scopeName in $scopeFile.Name)
{
$outputTable += @(
[pscustomobject]@{
` DHCPServer=$file.Name.ToString().Split(".")[0];
` ScopeName=$scopeName;
` SubnetMask=$scopeFile.SubnetMask;
` StartRange=$scopeFile.StartRange;
` EndRange=$scopeFile.EndRange;
` ScopeID=$scopeFile.ScopeID
` State=$scopeFile.State
}
)
}
}
$outputTable | ft
Current output:
Expected output:
DHCPServerName,ScopeName,SubnetMask,StartRange,EndRange,ScopeID,State
server1,london,255.255.0.0,192.168.0.1,192.168.0.254,192.168.0.1,Active
server1,london,255.255.0.0,192.168.1.1,192.168.0.254,192.168.1.1,Active
server1,london,255.255.0.0,192.168.1.1,192.168.0.254,192.168.1.1,NotActive