SlideShare a Scribd company logo
Service Intergration 
Jang Jaemin 
jaeminj@gmail.com
Openssh + authentication key(1) 
fabio@morpheus:~$ ssh-keygen 
Generating public/private rsa key pair. 
Enter file in which to save the key (/home/fabio/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/fabio/.ssh/id_rsa. 
Your public key has been saved in /home/fabio/.ssh/id_rsa.pub. 
The key fingerprint is: 
44:3e:ef:58:94:15:52:c2:88:ca:ab:21:43:53:3d:42 fabio@morpheus 
fabio@morpheus:~$ 
fabio@morpheus:~$ ssh-keygen -p 
Enter file in which the key is (/home/fabio/.ssh/id_rsa): 
Key has comment '/home/fabio/.ssh/id_rsa' 
Enter new passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved with the new passphrase. 
fabio@morpheus:~$
Openssh + authentication key(2) 
Install the public key on the servers 
fabio@morpheus:~$ ssh-copy-id -i .ssh/id_rsa.pub ornellas@apanela.com 
15 
ornellas@apanela.com's password: 
Now try logging into the machine, with "ssh 'ornellas@apanela.com'", and check in: 
.ssh/authorized_keys 
to make sure we haven't added extra keys that you weren't expecting. 
fabio@morpheus:~$
freesshd(1) 
Overview 
Install and configure FreeSSHd on the server 
Create keys 
configure Putty to connect to the server 
Install FreeSSHd 
Download FreeSSHd from http://www.freesshd.com/?ctt=download 
Double click to start installer on the server 
As a service 
Accept all other defaults
freesshd(2) 
Configure FreeSSHd 
Open FreeSSHd settings (may have to kill the service and start manually to get the GUI) 
SSH tab: 
Max number = 2 
idle = 600 
Authentication tab 
Pub key folder = C:Program Files (x86)freeSSHdkeys 
Password auth = disabled 
Pub key auth = required 
Users tab 
add 
login=chef 
auth = 'Pub key (ssh only)' 
user can use = shell 
click OK
freesshd(3) 
Generate Public and Private keys 
Open PuttyGen 
Click ‘Generate’ 
move the mouse pointer around as instructed to generate the key 
Save a Putty compatible private key 
Click ‘Save private key’ 
Save this to the client PC, Putty will need this 
You should really save with a passphrase for extra security 
Save OpenSSL compatible private key for Chef knife 
‘Conversions’ menu > ‘Export OpenSSH Key’ > save as a *.pem 
Save the public key 
Copy the contents of ‘Public key for pasting into OpenSSH authorized file:’ and paste into a textfile. 
rename this file ‘chef’ (no file extension, the filename must match the user login name created drop this file into the public key folder C:Program Files (x86)freeSSHdkeys on the server.
freesshd(4) 
Connecting with Putty 
Open Putty (or Putty portable) 
Enter the IP address of the server 
Connection type = SSH (obviously!) 
In the left menu tree 
Connection > SSH > Auth > ‘Private key file for authentication:’ > click browse 
Select the private key that was generated above 
Click ‘Open’ 
when prompted ‘login:’ > enter ‘chef’ > hit enter 
If the private key was saved with a passphrase then enter this when prompted 
You should now be connected to the server. 
ssh -o ConnectTimeOut=10 -o Port='22' -o IdentityFile=key/'id_rsa'  
-o GSSAPIAuthentication=no -o PasswordAuthentication=no  
-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null  
-o LogLevel=ERROR 'XXX'@'192.168.XXX.XXX'
Sshclient.php 
<? 
$this->cli= parent::newClass("sshclient", $ssh_conf); 
$this->cli->exec( $cmd); 
$data['stdout'] = $this->stdout ; 
$data['stderr'] = $this->stderr; 
?>
JSON, Rest Api , bash, PHP, 
Powershell
Json (Javascript Object Notation) 
{ 
"glossary": { 
"title": "example glossary", 
"GlossDiv": { 
"title": "S", 
"GlossList": { 
"GlossEntry": { 
"ID": "SGML", 
"SortAs": "SGML", 
"GlossTerm": "Standard Generalized Markup Language", 
"Acronym": "SGML", 
"Abbrev": "ISO 8879:1986", 
"GlossDef": { 
"para": "A meta-markup language, used to create markup languages such as DocBook.", 
"GlossSeeAlso": ["GML", "XML"] 
}, 
"GlossSee": "markup" 
} 
} 
} 
} 
}
Restful api 
HTTP Method URI Action 
GET http://[hostname]/todo/api/v1.0/tasks 
Retrieve list of 
tasks 
GET 
http://[hostname]/todo/api/v1.0/tasks/ 
[task_id] 
Retrieve a task 
POST http://[hostname]/todo/api/v1.0/tasks 
Create a new 
task 
PUT 
http://[hostname]/todo/api/v1.0/tasks/ 
[task_id] 
Update an 
existing task 
DELETE 
http://[hostname]/todo/api/v1.0/tasks/ 
[task_id] 
Delete a task
PHP Server Side (1) 
<?php 
switch ($_SERVER['REQUEST_METHOD'] ) { 
case 'PUT': 
case 'POST': 
case 'GET': 
case 'HEAD': 
case 'DELETE': 
case 'OPTIONS': 
break; 
default: 
break; 
} 
?> 
.htaccess 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-s 
RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,NC,L] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^(.*)$ api.php [QSA,NC,L] 
RewriteCond %{REQUEST_FILENAME} -s 
RewriteRule ^(.*)$ api.php [QSA,NC,L] 
</IfModule>
PHP Server Side (2) 
<?php 
$request = file_get_contents('php://input'); 
// return associative array of JSON 
$input = json_decode($request, true); 
$input['request'] = $request; 
$input['rx_datetime'] = date('Y-m-d H:i:s') ; 
header("Content-type: application/json"); 
echo json_encode($input); 
?>
Bash 
curl -i -X POST -H "Content-Type: application/json ; charset=UTF-8"  
-d '{"username":"xyz","password":"xyz"}' http://localhost:3000/api/login 
curl -i -d @credentials.json -H "Content-Type: application/json"  
http://localhost:3000/api/login 
-X [PUT | POST | GET | DELETE] 
http://blogs.plexibus.com/2010/04/12/rest-esting-with-curl-file-handling/
PHP 
<? 
$data = array("name" => "Hagrid", "age" => "36"); 
$data_string = json_encode($data); 
$ch = curl_init('http://api.local/rest/users'); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 
'Content-Type: application/json', 
'Content-Length: ' . strlen($data_string)) 
); 
$result = curl_exec($ch, true); 
curl_Close($ch) 
$data = json_decode($result, true) ; 
print_r($data) 
?>
Powershell Client(1) 
http://www.powershellcookbook.com/recipe/Vlhv/interact-with-rest-based-web-apis 
Invoke-RestMethod cmdlet 
PS > $url = "https://api.stackexchange.com/2.0/questions/unanswered" + 
"?order=desc&sort=activity&tagged=powershell&pagesize=10&site=stackoverflow" 
PS > $result = Invoke-RestMethod $url 
PS > $result.Items | Foreach-Object { $_.Title; $_.Link; "" } 
PS> $contact = @{ 
first_name="Jack"; 
last_name="Smith"; 
emails=@{preferred="jsmith@contoso.com";business="Jack.Smith@contoso.com"} 
} | ConvertTo-Json 
PS> Invoke-RestMethod -Uri "$ApiUri/me/contacts?access_token=$AccessToken" 
-Method Post -ContentType "application/json" -Body $contact
Powershell Client(2) 
$url = "http://www.seismi.org/api/eqs" 
$request = [System.Net.WebRequest]::Create($url) 
$request.Method="Get" 
$response = $request.GetResponse() 
$requestStream = $response.GetResponseStream() 
$readStream = New-Object System.IO.StreamReader $requestStream 
$data=$readStream.ReadToEnd() 
if($response.ContentType -match "application/xml") { 
$results = [xml]$data 
} elseif($response.ContentType -match "application/json") { 
$results = $data | ConvertFrom-Json 
} else { 
try { 
$results = [xml]$data 
} catch { 
$results = $data | ConvertFrom-Json 
} 
} 
$results

More Related Content

PPTX
08 php-files
TXT
My shell
PPTX
Ch3(working with file)
TXT
C99
TXT
C99[2]
PPTX
Cryptography for the mere mortals
PPTX
Cryptography for the mere mortals - for phpXperts Seminar 2011 by Hasin and Tonu
PDF
How to stand on the shoulders of giants
08 php-files
My shell
Ch3(working with file)
C99
C99[2]
Cryptography for the mere mortals
Cryptography for the mere mortals - for phpXperts Seminar 2011 by Hasin and Tonu
How to stand on the shoulders of giants

What's hot (20)

PPTX
preventing sqli and xss by ravi rajput in owasp meet ahmedabad
PDF
The Joy of Smartmatch
PDF
ZeroMQ Is The Answer: DPC 11 Version
PPTX
Creating a keystroke logger in unix shell scripting
PDF
ZeroMQ Is The Answer
PDF
News of the Symfony2 World
PPTX
Php functions
PDF
&lt;img src="../i/r_14.png" />
PDF
Perl6 grammars
PDF
ZeroMQ: Messaging Made Simple
PDF
Not Really PHP by the book
PDF
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
PDF
Redis for your boss
PDF
Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020
PPTX
On secure application of PHP wrappers
PDF
Redis for your boss 2.0
PDF
Redis for the Everyday Developer
PDF
Whispered secrets
PPTX
User registration and login using stored procedure in php
PDF
神に近づくx/net/context (Finding God with x/net/context)
preventing sqli and xss by ravi rajput in owasp meet ahmedabad
The Joy of Smartmatch
ZeroMQ Is The Answer: DPC 11 Version
Creating a keystroke logger in unix shell scripting
ZeroMQ Is The Answer
News of the Symfony2 World
Php functions
&lt;img src="../i/r_14.png" />
Perl6 grammars
ZeroMQ: Messaging Made Simple
Not Really PHP by the book
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
Redis for your boss
Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020
On secure application of PHP wrappers
Redis for your boss 2.0
Redis for the Everyday Developer
Whispered secrets
User registration and login using stored procedure in php
神に近づくx/net/context (Finding God with x/net/context)
Ad

Viewers also liked (10)

PDF
Wireless Feature Update
PPTX
Enterprise Network Design and Deployment
PDF
Overview of web services
PPT
Introduction to Patterns in WebSphere Message Broker
PPT
WebSphere Message Broker Training | IBM WebSphere Message Broker Online Training
PDF
WebSphere Message Broker installation guide
PDF
WebSphere Message Broker Training Agenda
PPTX
Ibm message broker basic
PDF
WebSphere Message Broker Application Development Training
PPT
Introduction to WebSphere Message Broker
Wireless Feature Update
Enterprise Network Design and Deployment
Overview of web services
Introduction to Patterns in WebSphere Message Broker
WebSphere Message Broker Training | IBM WebSphere Message Broker Online Training
WebSphere Message Broker installation guide
WebSphere Message Broker Training Agenda
Ibm message broker basic
WebSphere Message Broker Application Development Training
Introduction to WebSphere Message Broker
Ad

Similar to Service intergration (20)

PDF
PHP SA 2014 - Releasing Your Open Source Project
DOC
PHP code examples
PDF
Blog Hacks 2011
PDF
Php Security
ODP
Introduction to devsecdotio
PDF
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
PPT
Hacking with hhvm
PDF
Nko workshop - node js crud & deploy
DOC
How to send files to remote server via ssh in php
PPT
secure php
PDF
Legacy applications - 4Developes konferencja, Piotr Pasich
PPT
PHP POWERPOINT SLIDES
PPTX
php part 2
PDF
PHP Backdoor: The rise of the vuln
PDF
Tomáš Čorej - OpenSSH
PDF
PHP and Databases
PDF
Writing and Publishing Puppet Modules - PuppetConf 2014
PPTX
Php talk
PDF
Ssh cookbook v2
PDF
Ssh cookbook
PHP SA 2014 - Releasing Your Open Source Project
PHP code examples
Blog Hacks 2011
Php Security
Introduction to devsecdotio
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Hacking with hhvm
Nko workshop - node js crud & deploy
How to send files to remote server via ssh in php
secure php
Legacy applications - 4Developes konferencja, Piotr Pasich
PHP POWERPOINT SLIDES
php part 2
PHP Backdoor: The rise of the vuln
Tomáš Čorej - OpenSSH
PHP and Databases
Writing and Publishing Puppet Modules - PuppetConf 2014
Php talk
Ssh cookbook v2
Ssh cookbook

Recently uploaded (20)

PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPTX
Funds Management Learning Material for Beg
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPTX
Introduction to Information and Communication Technology
PPTX
SAP Ariba Sourcing PPT for learning material
PPTX
QR Codes Qr codecodecodecodecocodedecodecode
PPTX
artificial intelligence overview of it and more
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
DOCX
Unit-3 cyber security network security of internet system
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Triggering QUIC, presented by Geoff Huston at IETF 123
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PDF
Paper PDF World Game (s) Great Redesign.pdf
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPTX
presentation_pfe-universite-molay-seltan.pptx
Introuction about WHO-FIC in ICD-10.pptx
Funds Management Learning Material for Beg
SASE Traffic Flow - ZTNA Connector-1.pdf
Introduction to Information and Communication Technology
SAP Ariba Sourcing PPT for learning material
QR Codes Qr codecodecodecodecocodedecodecode
artificial intelligence overview of it and more
Module 1 - Cyber Law and Ethics 101.pptx
Job_Card_System_Styled_lorem_ipsum_.pptx
RPKI Status Update, presented by Makito Lay at IDNOG 10
Unit-3 cyber security network security of internet system
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Cloud-Scale Log Monitoring _ Datadog.pdf
Triggering QUIC, presented by Geoff Huston at IETF 123
Decoding a Decade: 10 Years of Applied CTI Discipline
Paper PDF World Game (s) Great Redesign.pdf
Unit-1 introduction to cyber security discuss about how to secure a system
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
presentation_pfe-universite-molay-seltan.pptx

Service intergration

  • 1. Service Intergration Jang Jaemin jaeminj@gmail.com
  • 2. Openssh + authentication key(1) fabio@morpheus:~$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/fabio/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/fabio/.ssh/id_rsa. Your public key has been saved in /home/fabio/.ssh/id_rsa.pub. The key fingerprint is: 44:3e:ef:58:94:15:52:c2:88:ca:ab:21:43:53:3d:42 fabio@morpheus fabio@morpheus:~$ fabio@morpheus:~$ ssh-keygen -p Enter file in which the key is (/home/fabio/.ssh/id_rsa): Key has comment '/home/fabio/.ssh/id_rsa' Enter new passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved with the new passphrase. fabio@morpheus:~$
  • 3. Openssh + authentication key(2) Install the public key on the servers fabio@morpheus:~$ ssh-copy-id -i .ssh/id_rsa.pub ornellas@apanela.com 15 ornellas@apanela.com's password: Now try logging into the machine, with "ssh 'ornellas@apanela.com'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. fabio@morpheus:~$
  • 4. freesshd(1) Overview Install and configure FreeSSHd on the server Create keys configure Putty to connect to the server Install FreeSSHd Download FreeSSHd from http://www.freesshd.com/?ctt=download Double click to start installer on the server As a service Accept all other defaults
  • 5. freesshd(2) Configure FreeSSHd Open FreeSSHd settings (may have to kill the service and start manually to get the GUI) SSH tab: Max number = 2 idle = 600 Authentication tab Pub key folder = C:Program Files (x86)freeSSHdkeys Password auth = disabled Pub key auth = required Users tab add login=chef auth = 'Pub key (ssh only)' user can use = shell click OK
  • 6. freesshd(3) Generate Public and Private keys Open PuttyGen Click ‘Generate’ move the mouse pointer around as instructed to generate the key Save a Putty compatible private key Click ‘Save private key’ Save this to the client PC, Putty will need this You should really save with a passphrase for extra security Save OpenSSL compatible private key for Chef knife ‘Conversions’ menu > ‘Export OpenSSH Key’ > save as a *.pem Save the public key Copy the contents of ‘Public key for pasting into OpenSSH authorized file:’ and paste into a textfile. rename this file ‘chef’ (no file extension, the filename must match the user login name created drop this file into the public key folder C:Program Files (x86)freeSSHdkeys on the server.
  • 7. freesshd(4) Connecting with Putty Open Putty (or Putty portable) Enter the IP address of the server Connection type = SSH (obviously!) In the left menu tree Connection > SSH > Auth > ‘Private key file for authentication:’ > click browse Select the private key that was generated above Click ‘Open’ when prompted ‘login:’ > enter ‘chef’ > hit enter If the private key was saved with a passphrase then enter this when prompted You should now be connected to the server. ssh -o ConnectTimeOut=10 -o Port='22' -o IdentityFile=key/'id_rsa' -o GSSAPIAuthentication=no -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR 'XXX'@'192.168.XXX.XXX'
  • 8. Sshclient.php <? $this->cli= parent::newClass("sshclient", $ssh_conf); $this->cli->exec( $cmd); $data['stdout'] = $this->stdout ; $data['stderr'] = $this->stderr; ?>
  • 9. JSON, Rest Api , bash, PHP, Powershell
  • 10. Json (Javascript Object Notation) { "glossary": { "title": "example glossary", "GlossDiv": { "title": "S", "GlossList": { "GlossEntry": { "ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": { "para": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": ["GML", "XML"] }, "GlossSee": "markup" } } } } }
  • 11. Restful api HTTP Method URI Action GET http://[hostname]/todo/api/v1.0/tasks Retrieve list of tasks GET http://[hostname]/todo/api/v1.0/tasks/ [task_id] Retrieve a task POST http://[hostname]/todo/api/v1.0/tasks Create a new task PUT http://[hostname]/todo/api/v1.0/tasks/ [task_id] Update an existing task DELETE http://[hostname]/todo/api/v1.0/tasks/ [task_id] Delete a task
  • 12. PHP Server Side (1) <?php switch ($_SERVER['REQUEST_METHOD'] ) { case 'PUT': case 'POST': case 'GET': case 'HEAD': case 'DELETE': case 'OPTIONS': break; default: break; } ?> .htaccess <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-s RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,NC,L] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.*)$ api.php [QSA,NC,L] RewriteCond %{REQUEST_FILENAME} -s RewriteRule ^(.*)$ api.php [QSA,NC,L] </IfModule>
  • 13. PHP Server Side (2) <?php $request = file_get_contents('php://input'); // return associative array of JSON $input = json_decode($request, true); $input['request'] = $request; $input['rx_datetime'] = date('Y-m-d H:i:s') ; header("Content-type: application/json"); echo json_encode($input); ?>
  • 14. Bash curl -i -X POST -H "Content-Type: application/json ; charset=UTF-8" -d '{"username":"xyz","password":"xyz"}' http://localhost:3000/api/login curl -i -d @credentials.json -H "Content-Type: application/json" http://localhost:3000/api/login -X [PUT | POST | GET | DELETE] http://blogs.plexibus.com/2010/04/12/rest-esting-with-curl-file-handling/
  • 15. PHP <? $data = array("name" => "Hagrid", "age" => "36"); $data_string = json_encode($data); $ch = curl_init('http://api.local/rest/users'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data_string)) ); $result = curl_exec($ch, true); curl_Close($ch) $data = json_decode($result, true) ; print_r($data) ?>
  • 16. Powershell Client(1) http://www.powershellcookbook.com/recipe/Vlhv/interact-with-rest-based-web-apis Invoke-RestMethod cmdlet PS > $url = "https://api.stackexchange.com/2.0/questions/unanswered" + "?order=desc&sort=activity&tagged=powershell&pagesize=10&site=stackoverflow" PS > $result = Invoke-RestMethod $url PS > $result.Items | Foreach-Object { $_.Title; $_.Link; "" } PS> $contact = @{ first_name="Jack"; last_name="Smith"; emails=@{preferred="jsmith@contoso.com";business="Jack.Smith@contoso.com"} } | ConvertTo-Json PS> Invoke-RestMethod -Uri "$ApiUri/me/contacts?access_token=$AccessToken" -Method Post -ContentType "application/json" -Body $contact
  • 17. Powershell Client(2) $url = "http://www.seismi.org/api/eqs" $request = [System.Net.WebRequest]::Create($url) $request.Method="Get" $response = $request.GetResponse() $requestStream = $response.GetResponseStream() $readStream = New-Object System.IO.StreamReader $requestStream $data=$readStream.ReadToEnd() if($response.ContentType -match "application/xml") { $results = [xml]$data } elseif($response.ContentType -match "application/json") { $results = $data | ConvertFrom-Json } else { try { $results = [xml]$data } catch { $results = $data | ConvertFrom-Json } } $results