'Converting Object to string in Powershell

Can anyone provide some help please. I have JSON script where my datapath and file names are stored. However, in Powershell, I am able to get the path in the string format but the filename is in array. I am expecting the output to be, for eample C:\Dep\reports\P1.sql C:\Dep\reports\P2.sql C:\Dep\reports\P3.sql

enter image description here

cls

$ReportConfiguration = Get-Content -path  "C:\Users\asingh\Documents\PowerShell Scripts\JSON\stackOverflow.json" | ConvertFrom-JSon

$ReportFolders = @($ReportConfiguration.ReportScripts | Get-Member -Type NoteProperty).Name
$reportPath = $ReportConfiguration.ReportScripts.ReportFiles.Location


foreach($folder in $ReportFolders)
{
    #Display folder name
    Write-Host  $folder -ForegroundColor Green
    
    #
    $subReportsFolders = @($ReportConfiguration.ReportScripts.$folder | Get-Member -Type NoteProperty).Name
    write-host "No. of subFolders = " $subReportsFolders.Count
    Write-Host "subfolder:  "  $subReportsFolders 
    #
    
    for ($ReportCount = 0 ; $ReportCount -le $QueryCount.Count ; $ReportCount++)
    {      
          $ReportPath + $folder + $ReportConfiguration.ReportScripts.$folder[$ReportCount]        
    }

    Write-Host(" `n" )
}

{
    "ReportScripts": 
    {
        "ReportFiles":
        {
            "Location": "C:\\Dep\\Test\\"
        },
        
        "Test1":
        {
            "Schema_File" : "S1.sql",
            "Proc_File": "P1.sql"
        },
                
        "Test2":
        {
            "Schema_File" : "S2.sql",
            "Proc_File": "P2.sql"
        }
    }
}


Solution 1:[1]

##clear host 
cls
$ReportConfiguration = Get-Content -path  "C:\Users\asingh\Documents\PowerShell Scripts\JSON\stackOverflow.json" | ConvertFrom-JSon

$ReportFolders = @($ReportConfiguration.ReportScripts | Get-Member -Type NoteProperty).Name
$reportPath = $ReportConfiguration.ReportScripts.ReportFiles.Location


foreach($folder in $ReportFolders)
{
    #Display folder name
    Write-Host  $folder -ForegroundColor Green
    
    #
    $subReportsFolders = @($ReportConfiguration.ReportScripts.$folder | Get-Member -Type NoteProperty).Name
    write-host "No. of subFolders = " $subReportsFolders.Count
    Write-Host "subfolder:  "  $subReportsFolders 
    #
    
    for ($ReportCount = 0 ; $ReportCount -le $QueryCount.Count ; $ReportCount++)
    {      
          $ReportPath + $folder + $ReportConfiguration.ReportScripts.$folder[$ReportCount]        
    }

# Here is the fix
"C:\test\" + $ReportConfiguration.ReportScripts.$folder.Proc_File
"C:\test\" + $ReportConfiguration.ReportScripts.$folder.Schema_File

Write-Host(" `n" )
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 another victim of the mouse