0

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

1
  • This looks like a JSON response. Please employ ConvertFrom-JSON and parse whatever object you receive as a complex but otherwise normal Powershell object. Commented Apr 18, 2017 at 6:41

1 Answer 1

1
$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.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked perfectly and I see where I was making my mistakes, thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.