Monday, June 29, 2015

Powershell Scripts - Get-Parse & Publish-Parse - upload and download data from Parse.com Core DB

If you haven't checked out Parse as a hosted database platform for your website and/or app, you should.  They are free to start out and when your site or app takes off, they scale up with your traffic.  It's great for startups.  I didn't see a connector in Powershell to upload/download data from the core DB, so I made a pair of functions to do just that. They require Invoke-RestMethod which requires Powershell version 3 or later.

Lets try to upload a very simple table of 10 items, 2 columns:

PS C:\> $Data | FT -AutoSize

   code available
   ---- ---------
4993918      True
5449831      True
9565284      True
9251223      True
6062778      True
5107628      True
3599651      True
6477287      True
7101669      True
8115872      True


PS C:\> Publish-Parse -Class 'Codes' -AppID $AppID -APIKey $APIKey -Data $Data

createdAt                objectId  
---------                --------  
2015-06-29T23:42:14.104Z pmgrk5M87c
2015-06-29T23:42:14.330Z ivWv0Va6vE
2015-06-29T23:42:14.552Z Srj9Rcsvek
2015-06-29T23:42:14.766Z 4Muyx5v3kc
2015-06-29T23:42:14.978Z 6o4UrWc12J
2015-06-29T23:42:15.209Z 4EKTi7ZkTl
2015-06-29T23:42:15.423Z 6LMOBaSlbw
2015-06-29T23:42:15.646Z VzEgWXYbCV
2015-06-29T23:42:15.858Z YRIyxUD3Ue
2015-06-29T23:42:16.080Z UJgd2vfP5Y


I can see the new table in my web data browser in Parse:





Lets try to get that data back. Notice how Parse adds extra fields; if you don't want this in your data, use Select -ExcludeProperty to remove them.

PS C:\> Get-Parse -Class 'Codes' -AppID $AppID -APIKey $APIKey  | FT -AutoSize

available    code createdAt                objectId   updatedAt               
---------    ---- ---------                --------   ---------               
     True 4993918 2015-06-29T23:42:14.104Z pmgrk5M87c 2015-06-29T23:42:14.104Z
     True 5449831 2015-06-29T23:42:14.330Z ivWv0Va6vE 2015-06-29T23:42:14.330Z
     True 9565284 2015-06-29T23:42:14.552Z Srj9Rcsvek 2015-06-29T23:42:14.552Z
     True 9251223 2015-06-29T23:42:14.766Z 4Muyx5v3kc 2015-06-29T23:42:14.766Z
     True 6062778 2015-06-29T23:42:14.978Z 6o4UrWc12J 2015-06-29T23:42:14.978Z
     True 5107628 2015-06-29T23:42:15.209Z 4EKTi7ZkTl 2015-06-29T23:42:15.209Z
     True 3599651 2015-06-29T23:42:15.423Z 6LMOBaSlbw 2015-06-29T23:42:15.423Z
     True 6477287 2015-06-29T23:42:15.646Z VzEgWXYbCV 2015-06-29T23:42:15.646Z
     True 7101669 2015-06-29T23:42:15.858Z YRIyxUD3Ue 2015-06-29T23:42:15.858Z
     True 8115872 2015-06-29T23:42:16.080Z UJgd2vfP5Y 2015-06-29T23:42:16.080Z


PS C:\> Get-Parse -Class 'Codes' -AppID $AppID -APIKey $APIKey  -objectID "pmgrk5M87c","VzEgWXYbCV" | FT -AutoSize

available    code createdAt                objectId   updatedAt               
---------    ---- ---------                --------   ---------               
     True 4993918 2015-06-29T23:42:14.104Z pmgrk5M87c 2015-06-29T23:42:14.104Z
     True 6477287 2015-06-29T23:42:15.646Z VzEgWXYbCV 2015-06-29T23:42:15.646Z



Source Code:

No comments: