Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Convert JSON data into usable variables

$
0
0

Hello,

I am writing a Power shell script to query AWS DynamoDB and retrieve some data (uses the AWS CLI). The two pieces of data I am interested in are "foldername" and "quota" size.

I would like to place those two pieces of information into two separate variables, $folder and $quota. From there I will use those variables in a update user quota information for a Windows FSRM implementation.

Below is the script that I have so far, the problem I've got is that I don't know how to turn the JSON output which I get from the AWS CLI dynamoDB into the variables. I've made a start by conventing the JSON data into a PowerShell object, but as you can see from the script below, it's full of symbols I don't want, "@= {}". Any help would be much appreciated.

 

### Connect to DynamoDB to extract the new Quota Data

$json = aws dynamodb scan --table-name quotapending --region ap-southeast-2

### Output the results to a JSON file

$json | Out-File -FilePath F:\MyJson.json

### Set the $file variable to the output JSON file

$file ="F:\MyJson.json"

### Create a Powershell object called $Data from the JSON strings

$data = Get-content $file| out-string | ConvertFrom-Json

### Print out the contents of the new PowerShell Object

$data.Items | Format-table

 

createdate                                                 quota                                                foldername

----------                                                     -----                                                ----------

@{S=2014-04-08 03:41:32}                      @{N=100}                                      @{S=001070-112233-1236386}

@{S=2014-04-08 03:38:31}                      @{N=100}                                      @{S=1309506-1}

@{S=2014-04-08 05:01:04}                      @{N=100}                                      @{S=1309506-1}

@{S=2014-04-07 17:09:58}                      @{N=100}                                      @{S=0112233-1}

@{S=2014-04-08 03:34:20}                      @{N=200}                                     @{S=1309506-1.backup}

 

@{S=2014-04-08 05:01:04}                      @{N=100}                                      @{S=1309506-1.backup}


Viewing all articles
Browse latest Browse all 6937

Latest Images

Trending Articles



Latest Images