PowerShell 7.3 - Difficulty with Combining Multiple JSON Files into a Single Object
I've searched everywhere and can't find a clear answer. I'm sure I'm missing something obvious here, but I'm trying to merge multiple JSON files into a single PowerShell object, but I'm running into issues with how the data is structured. I have a series of JSON files that contain user information, and I want to combine them into one comprehensive object. Each file has a similar structure, like this: ```json { "UserId": 1, "Name": "Alice", "Email": "alice@example.com" } ``` When I use `Get-Content` to read all the files and `ConvertFrom-Json` to parse them, I find that they aren't being merged correctly. Here's the code I've written so far: ```powershell $files = Get-ChildItem -Path "C:\Users\JSONFiles\*.json" $combined = @() foreach ($file in $files) { $content = Get-Content -Path $file.FullName -Raw | ConvertFrom-Json $combined += $content } ``` After running this, I expected `$combined` to contain an array of user objects, but instead, I'm getting a single object with properties from the last JSON file only. The final output looks like this: ```powershell UserId Name Email ------- ---- ----- 1 Bob bob@example.com ``` It seems like my approach is overwriting the previous entries instead of accumulating them. I've also considered using `+=` to add to the array, but it still doesn't yield the desired result. How can I ensure that I combine all user information into one array properly? Is there a better way to handle this operation with respect to performance and best practices in PowerShell 7.3? Has anyone else encountered this? My development environment is Linux. What's the best practice here?