Last active
April 25, 2018 13:05
-
-
Save gitfvb/5e467f03fef0f7071c82eb78df28e32b to your computer and use it in GitHub Desktop.
load odata v4 sources via powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hints: https://github.com/PowerShell/ODataUtils | |
# some preparation work for connection to a Redfish endpoint | |
# enable TLS v1.1 as required by Redfish spec | |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls11 | |
# allow self-signed server certificates | |
if ([System.Net.ServicePointManager]::CertificatePolicy.GetType().Name -ne 'TrustAllCertsPolicy') | |
{ | |
Add-Type 'using System.Net;using System.Security.Cryptography.X509Certificates;public class TrustAllCertsPolicy:ICertificatePolicy {public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate,WebRequest request, int certificateProblem) {return true;}}' | |
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy | |
} | |
Export-ODataEndpointProxy -Uri "http://services.odata.org/V4/odata/odata.svc/" -Force -CmdletAdapter ODataV4Adapter -OutputModule "C:\Users\Florian\Desktop\20180424\odata\generated" -AllowUnsecureConnection | |
# there is a bug in the generated files... remove in the generated.ps1 the reference to ServiceActions.cdxml | |
Import-Module "C:\Users\Florian\Desktop\20180424\odata\generated" -Force | |
Get-Product -AllowUnsecureConnection -AllowAdditionalData | Out-GridView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this approach seems much nicer, as the result will be delivered back in json and brings more results | |
# without the need to transform the data in powershell | |
# inspired by https://pholpar.wordpress.com/2017/03/29/working-with-the-rest-odata-interface-from-powershell/ | |
# https://audministrator.wordpress.com/2015/01/03/getting-odata-using-powershell/ | |
# http://odata.github.io/odata.net/#04-01-basic-crud-operations | |
$headers = @{ ‘Accept’ = ‘application/json; odata=verbose’} | |
$result = Invoke-RestMethod -uri "http://services.odata.org/Northwind/Northwind.svc/Orders" -Headers $headers | |
$result.d.results | Out-GridView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment