ETHER
ETHER

Reputation: 47

Grabbing and Displaying data from html page Powershell

Hello Im making a simple command line tool, that will help me communicate/ grab data from my gaming server via SSH/Powershell. Im trying to grab some data from 192.95.23.181:11775(shows number of players, map name, variant, port, etc)

How do I grab specific data and display it with powershell. For Example

`$server = Invoke-WebRequest -URI 192.95.23.181:11775

PS C:\Users\Administrator> $server.Content

{"name":"#2 [US-EAST] Dedicated Community Infection Server","port":11774,"hostPlayer":"HaloInfect.Net","isDedicated":tr
ue,"sprintEnabled":"1","sprintUnlimitedEnabled":"0","assassinationEnabled":"1","VoIP":true,"teams":false,"map":"Green J
ourney","mapFile":"riverworld","variant":"Toxic Fatkid","variantType":"infection","status":"InGame","numPlayers":2,"max
Players":16,"xnkid":"5314a305e810484089d439e5089d24fe","xnaddr":"c53527ae684116459bdab2a2154fa4e6","players":[{"name":"
1321","score":0,"kills":0,"assists":0,"deaths":0,"team":0,"isAlive":true,"uid":"83217235a7e315bb"},{"name":"Max","score
":0,"kills":0,"assists":0,"deaths":0,"team":1,"isAlive":false,"uid":"f523149f39fc331e"}],"gameVersion":"1.106708_cert_m
s23___release","eldewritoVersion":"0.5.1.1"}
PS C:\Users\Administrator>`

Lets say I wanna grab the numbers after "numplayer: or the map name after "map", how can i write a script that will search and display this data.

Hope that make sense, thanks in advance

Upvotes: 0

Views: 250

Answers (1)

Vesper
Vesper

Reputation: 18757

$data=convertfrom-json $server.content
$data.numPlayers

Should do.

ConvertFrom-Json makes a normal Powershell object from your response, as it's in fact a JSON response. You can then query its fields directly. Should you need to send a JSON request, you should create an object with desired structure, then call ConvertTo-Json to get the string to send.

Upvotes: 1

Related Questions