We have a Web Service which is in JSON format(script) that needs to be converted to csv files and dropped to a fileshare location using powershell. All this needs to be captured on running a SSIS package. How can this be achieved?
# Set the filename to have the date suffix.
$fileName = "2758_RS-DM_AIRData" + (Get-Date -Format yyyyMMdd_hh) + ".csv"
$location = "C:\ExtractFilePowerShellWebService\Data"
New-Item -ItemType file -Name $fileName -Path $location
# delete if file exist
$FileName2 = (Join-Path $location $fileName)
if (Test-Path $FileName2) {
Remove-Item $FileName2
}
# Capture data from AIR Web Service
$webclient = new-object System.Net.WebClient
$webclient.Credentials = new-object System.Net.NetworkCredential("A", "B", "C")
$Json = $WebClient.Downloadstring("https://air.ciostage.accenture.com/ExternalServices/Application-service/Application(2758)")
$jsonserial= New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer
$jsonserial.MaxJsonLength = [int]::MaxValue
$appCollection = @()
$appObj = $jsonserial.DeserializeObject($Json)
foreach($app in $appObj.value){
$appObject = New-Object System.Object
$appObject | Add-Member -MemberType NoteProperty -Name "ApplicationId" -Value $app.ApplicationId
$appObject | Add-Member -MemberType NoteProperty -Name "ApplicationNm" -Value $app.ApplicationNm
$appObject | Add-Member -MemberType NoteProperty -Name "Application Tier" -Value $app.ServiceLevelOfferingNm
$appObject | Add-Member -MemberType NoteProperty -Name "Application Status" -Value $app.AppStatusNm
#$appObject | Add-Member -MemberType NoteProperty -Name "Description" -Value $app.Description
#$appObject | Add-Member -MemberType NoteProperty -Name "Acronym" -Value $app.Acronym
#$appObject | Add-Member -MemberType NoteProperty -Name "Url" -Value $app.Url
$appCollection += $appObject
}
#$appCollection | Export-Csv -Path "C:\ExtractFilePowerShellWebService\Data\2758_RS-DM_AIRData.csv" -notypeinformation
#extract data into CSV file.
$appCollection | Export-Csv -Path (Join-Path $location $fileName) -notypeinformation
When I run the script, csv file is created in the location mentioned but it is empty
Selectto flatten them or extract only the necessary fields