Functions/Data/Export-JSON.ps1
Function Export-JSON { Param ( # Input Object [Parameter(Mandatory=$true,ValueFromPipeline = $true,ValueFromPipelineByPropertyName = $true)] [psobject] $InputObject, [Parameter(Mandatory=$true)] [String] $Path, [Parameter(Mandatory=$false)] [int] $Depth = 10 ) Begin { # Instantiate Data Collection $DATA = [system.collections.arraylist]@() } Process {$ADD = $DATA.add($InputObject)} End { # Convert Data to JSON $JSON = $DATA | ConvertTo-Json -Depth $Depth # Output File with Proper Encoding to Path [IO.File]::WriteAllLines($Path,$JSON) } } |