Skip to content

Instantly share code, notes, and snippets.

@btipling
Last active June 2, 2020 19:53
Show Gist options
  • Save btipling/ee096da8b794deab6d621bf9b8ec41c4 to your computer and use it in GitHub Desktop.
Save btipling/ee096da8b794deab6d621bf9b8ec41c4 to your computer and use it in GitHub Desktop.
Just some JSON to parse.
{
"foo": 3,
"bar": 10
}
PS C:\Users\swart\projects\powershell_scripts> .\get_remote_data.ps1
PS C:\Users\swart\projects\powershell_scripts> Find-RemoteData -Name "bar"
10
PS C:\Users\swart\projects\powershell_scripts> Find-RemoteData -Name "foo"
3
PS C:\Users\swart\projects\powershell_scripts> (Find-RemoteData -Name "bar") + (Find-RemoteData -Name "foo")
13
PS C:\Users\swart\projects\powershell_scripts> Read-RemoteData
foo bar
--- ---
3 10
$global:dataURL = "https://gist.githubusercontent.com/btipling/ee096da8b794deab6d621bf9b8ec41c4/raw/d46f89efa3059c1e3915dafe5b438f4e41bcf859/foo.json"
function global:Read-RemoteData() {
Invoke-RestMethod -Uri $global:dataURL
}
function global:Find-RemoteData([string]$Name) {
$response = Invoke-WebRequest -Uri $global:dataURL
$data = $response.Content | ConvertFrom-Json -AsHashtable
[int] $data[$Name]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment