0

I worked with the following PS1 script and was able to export the objects to csv:

$secpasswd = ConvertTo-SecureString "password" -AsPlainText -Force 
$Cred = New-Object System.Management.Automation.PSCredential ('username', $secpasswd) 
$User = Invoke-RestMethod -Method 'Get' -uri "https://192.168.50.60/api/reports/v1/users" -Credential $Cred

$user.data | select-object 'user_name','email_id','user_status' | Export-Csv -path UserStatusTest2.csv -NoTypeInformation

The above script worked fine until I have limited users added in the table and CSV file had all the data. However when I increased the users, a blank CSV is getting created.

I tried Out-file and found that the out data is more than 2 MB in size and may be the cause of the issue. I don't know how to fix this. Please help

1 Answers1

0

possible problem on .data utilisation

modify

$user.data | select-object 'user_name','email_id','user_status' | Export-Csv -path UserStatusTest2.csv -NoTypeInformation

by

$user | select user_name, email_id, user_status | Export-Csv UserStatusTest2.csv -NoTypeInformation
Esperento57
  • 16,521
  • 3
  • 39
  • 45
  • I have tried this method but no luck. I think there is a limitation in powershell for json serialization and deserialization of the string size. I reduced some entries from the DB and ensured that the json string returned is under 2 MB. Ran the same Powershell script and could see that data is exported in the CSv file. Not sure how to fix this. – Udaysingh Chauhan Dec 05 '16 at 10:43