Iterating through JSON File PowerShell With For Loops
hello everyone,
posted question similar earlier yesterday , mistake of not being specific enough, guys can kindly me today. i working json file has nested array , need able call line of information whether in vnx, twx, xcx or kis, , when calls line in 1 of these needs call based on information on either line 1,2 ,3 or 4. whether first number mix of letters , numbers(serial #) or ip address.
**i new powershell , doing self teaching, please bare me**
displays of information thats not want, want able implement for-loop runs through , picks out devices(vnx, twx, xcx, kis) serial number , displays information
might add of information coming json file saved externally.
stand in terms of thinking go this
said learning go along pretty stuck on getting work, direction or appreciated. feel free tell me if wrong, open it, ill take constructive criticism :)
posted question similar earlier yesterday , mistake of not being specific enough, guys can kindly me today. i working json file has nested array , need able call line of information whether in vnx, twx, xcx or kis, , when calls line in 1 of these needs call based on information on either line 1,2 ,3 or 4. whether first number mix of letters , numbers(serial #) or ip address.
**i new powershell , doing self teaching, please bare me**
$json = (get-content c:\catalog.json -raw)$json| convertfrom-json
displays of information thats not want, want able implement for-loop runs through , picks out devices(vnx, twx, xcx, kis) serial number , displays information
#this sample file sample information plugged in { "vnx": [ {"vnx": "45t45t45t45","ip": "213","user": "sysadmin","password": "hi"}, {"vnx": "45t45t45t23e","ip": "213","user": "sysadmin","password": "hi"}, {"vnx": "3r43rd54t5t5","ip": "213","user": "sysadmin","password": "hi"}, {"vnx": "5y6y6ytry565","ip": "213","user": "sysadmin","password": "hi"}], "vpx":[ {"vpx": "u98u8u8u8","ip": "213","user": "sysadmin","password": "hi"}, {"vpx": "3e98u8u98","ip": "213","user": "sysadmin","password": "hi"}, {"vpx": "6yy5y65i4","ip": "213","user": "sysadmin","password": "hi"}, {"vpx": "3r43r5t45","ip": "213","user": "sysadmin","password": "hi"}], "centera": [ {"cen": "f438u9u9u","ip": "213","user": "sysadmin","password": "hi"}, {"cen": "23ee2d09i","ip": "213","user": "sysadmin","password": "hi"}, {"cen": "90i329id9","ip": "213","user": "sysadmin","password": "hi"}, {"cen": "32d9iid0i","ip": "213","user": "sysadmin","password": "hi"}], "vmx":[ {"vmx": "3d2d23dfe","ip": "213","user": "sysadmin","password": "hi"}, {"vmx": "1w21w2wf4","ip": "213","user": "sysadmin","password": "hi"}, {"vmx": "3e32e888u","ip": "213","user": "sysadmin","password": "hi"}, {"vmx": "z38ue328u","ip": "213","user": "sysadmin","password": "hi"}] }
might add of information coming json file saved externally.
stand in terms of thinking go this
$devices = $x | get-member -membertype properties | select-object -expandproperty name foreach($devices in $devices) { if(#dont know put in here....){ write-output "$devices #stuck......" } } foreach($devices in $devices) { if(#dont know put in here....){ write-output "$devices #stuck......" } } foreach($devices in $devices) { if(#dont know put in here....){ write-output "$devices #stuck......" } } foreach($devices in $devices) { if(#dont know put in here....){ write-output "$devices #stuck......" } } #just putting many deemed necessary
said learning go along pretty stuck on getting work, direction or appreciated. feel free tell me if wrong, open it, ill take constructive criticism :)
this 1 way fix json:
$json=@' [ {"name":"vnx", "id": "45t45t45t45", "ip": "213", "user": "sysadmin", "password": "hi"}, {"name":"vnx", "id": "45t45t45t23e", "ip": "213", "user": "sysadmin", "password": "hi"}, {"name":"vnx", "id": "3r43rd54t5t5", "ip": "213", "user": "sysadmin", "password": "hi"}, {"name":"vnx", "id": "5y6y6ytry565", "ip": "213", "user": "sysadmin", "password": "hi"}, {"name":"vpx", "id": "u98u8u8u8", "ip": "213", "user": "sysadmin", "password": "hi"} , {"name":"vpx", "id": "3e98u8u98", "ip": "213", "user": "sysadmin", "password": "hi"} , {"name":"vpx", "id": "6yy5y65i4", "ip": "213", "user": "sysadmin", "password": "hi"} , {"name":"vpx", "id": "3r43r5t45", "ip": "213", "user": "sysadmin", "password": "hi"} , {"name":"cen", "id": "f438u9u9u", "ip": "213", "user": "sysadmin", "password": "hi"} , {"name":"cen", "id": "23ee2d09i", "ip": "213", "user": "sysadmin", "password": "hi"} , {"name":"cen", "id": "90i329id9", "ip": "213", "user": "sysadmin", "password": "hi"} , {"name":"cen", "id": "32d9iid0i", "ip": "213", "user": "sysadmin", "password": "hi"} , {"name":"vmx", "id": "3d2d23dfe", "ip": "213", "user": "sysadmin", "password": "hi"} , {"name":"vmx", "id": "1w21w2wf4", "ip": "213", "user": "sysadmin", "password": "hi"} , {"name":"vmx", "id": "3e32e888u", "ip": "213", "user": "sysadmin", "password": "hi"} , {"name":"vmx", "id": "z38ue328u", "ip": "213", "user": "sysadmin", "password": "hi"} ] '@ | convertfrom-json $json | ft
why use json when can build objects in powershell.
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment