Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

BePUG - PowerShell and REST - Expanding your Horizon

1,764 views

Published on

Short overview on RESTful API and PowerShell.
Presented at the BePUG meeting of January 14th 2016.

Published in: Software
  • Be the first to comment

BePUG - PowerShell and REST - Expanding your Horizon

  1. 1. PowerShell and REST Expanding your Horizon Luc Dekens, PowerShell MVP, vExpert
  2. 2. Bio • Luc Dekens - Belgium • PowerShell MVP (2013-2015) • vExpert (2009-2015) • Co-author PowerCLI Reference • LucD on VMware VMTN • http://lucd.info • @LucD22
  3. 3. Agenda • REST • Cmdlet • Simple Run • Issues • Tools • Star Wars
  4. 4. REST • Representational State Transfer • (Alternative to SOAP) • Not a protocol, but an architecture ! • Constraints: Client-Server, Stateless, Cacheable, Layered, Uniform Interface… • HTTP/HTTPS • HTTP Verbs (GET, POST, PUT, DELETE…) • URI (Uniform Resource Identifiers) • RESTful APIs
  5. 5. REST Method + Base-Uri + Endpoint GET https://cloud.ravellosystems.com/api/v1/applications GET http://whois.arin.net/rest/nets;q=207.46.13.63
  6. 6. Cmdlet Invoke-RestMethod • Since PowerShell v3 • Improved in subsequent versions, but still some annoying “issues” present • Tries to detect the returned datatype + converts (ATOM, XML, JSON, Text) • Parameters = 23 (PS v5 build 10.0.10586.0) + Common parameters
  7. 7. Cmdlet Parameters MethodUseBasicParsing URIWebSession SessionVariable Credential UseDefaultCredentials CertificateThumbprint Certificate UserAgent DisableKeepAlive TimeoutSec HeadersMaximumRedirection Proxy ProxyCredential ProxyUseDefaultCredentials Body ContentType TransferEncoding Infile Outfile Passthru Authentication CmdletRequest Session
  8. 8. Running the cmdlet 1 • Minimal run • Default REST Method is Get • Format of return data • Filetype-like extension on URI • Header - ContentType
  9. 9. Running the cmdlet 2
  10. 10. Running the cmdlet 3 • Authentication - Basic
  11. 11. Issues – DateTime 1 • JSON uses Unix epoch (POSIX time) • Type is long (int64) • Converting DateTime issue • DateTime: ScriptProperty (added by ETS) • DisplayHint: NoteProperty (added by Get-Date)
  12. 12. Issues – DateTime 2 • Solution 1
  13. 13. Issues – DateTime 3 • Solution 2 • Formula: convert to UTC, subtract “01/01/70 00:00” • … and back
  14. 14. Issues – Depth 1 • ConvertTo-Json : default Depth is 2 !
  15. 15. Issues – Status • Invoke-RestMethod only returns data • Status/Error code is not included
  16. 16. Tools 1 • The REST API Reference for the application • Come in all sizes and formats
  17. 17. Tools 2 • A simulator • Advanced REST Client for Chrome
  18. 18. Tools 3 • A Capturing Tool • Fiddler4 • PostMan
  19. 19. Tools 4 • Send script REST API traffic through Fiddler4
  20. 20. Tools 5 • Keep track of what you are implementing (think module)
  21. 21. Star Wars 1
  22. 22. Star Wars 2
  23. 23. Why REST • It’s (relatively) easy ! • Many vendors/products offer a Restful API • MSFT: Azure, Exchange, SharePoint… • VMW: vRealize Suite • EMC: Avamar • … and many more • Common (most of the time) methodology • To watch (?): Odata + OAuth2
  24. 24. References • Invoke-Restmethod • RESTful API Tutorial • RESTful Web services: The basics • API Directory • GitHub
  25. 25. Q&A

×