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.

VMUG - Mastering PowerShell to Call RESTful API Endpoints

1,637 views

Published on

VMUG - Mastering PowerShell to Call RESTful API Endpoints

Published in: Technology

VMUG - Mastering PowerShell to Call RESTful API Endpoints

  1. 1. Mastering PowerShell To Call RESTful API Endpoints
  2. 2. Who is @ChrisWahl? VMware Certified Design Expert (VCDX) #104 Data Center Virtualization (DCV) Network Virtualization (NV)
  3. 3. 3 Technical Blog WahlNetwork.com Networking for VMware Administrators Over 30 hours of video training Pluralsight.com Datanauts – Busting IT Silos DatanautsPodcast.com Internet Resources
  4. 4. Networking for VMware Administrators 100% of royalties are being donated to the Alzheimer’s Association
  5. 5. 5
  6. 6. Can I Get The Deck? Yes. Yes you can.
  7. 7. 7 Why should you care?
  8. 8. 8 Why Should You Care?
  9. 9. 9 Rise of the generalist! Why Should You Care?
  10. 10. 10 Make disparate systems work together (fun) Why Should You Care?
  11. 11. 11 Feed your hungry orchestration engines Why Should You Care?
  12. 12. 12 Make buckets of cash Why Should You Care?
  13. 13. 13 It’s really easy to learn Why Should You Care?
  14. 14. 14 The ecosystem has done most of the work Why Should You Care?
  15. 15. 15 But, most of all …
  16. 16. 16
  17. 17. 18 The first step!
  18. 18. 19 PowerShell Version 4 … or better
  19. 19. 20 The second step!
  20. 20.  Console  The command line interface  Microsoft.PowerShell_profile.ps1  ISE  Integrated Scripting Environment  Microsoft.PowerShellISE_profile.ps1  Console + ISE  profile.ps1 Profiles make life easier and happier Set up your profile
  21. 21.  Current User: %USERPROFILE%DocumentsWindowsPowerShell  All Users: %WINDIR%System32WindowsPowerShellv1.0 Profiles make life easier and happier Drop in your profile
  22. 22. Set-ExecutionPolicy Bypass Set-Location C:DropboxCode if ($psISE) { Start-Steroids Clear-Host Write-Host 'BEAST MODE (╯°□°)╯︵ ┻━┻' } Write yourself fun messages Self motivation for the win!
  23. 23. Set-ExecutionPolicy Bypass Set-Location C:DropboxCode if ($psISE) { Start-Steroids Clear-Host Write-Host 'BEAST MODE (╯°□°)╯︵ ┻━┻' } Write yourself fun messages Self motivation for the win!
  24. 24. 25 The third step!
  25. 25. 27 Everyone who knows something today… Didn’t know it yesterday
  26. 26. 28 Let’s dig into the code
  27. 27. Cmdlets for Calling a RESTful API • Invoke-WebRequest – Returns the entire response – Status, headers, body content, etc. • Invoke-RestMethod – Returns only the content from the response 29
  28. 28. Endpoints (and Resources) • Endpoints are expressed as URIs – Uniform Resource Identifier – Example endpoint: https://the.device.url/system/version – Used to access a resource • Should be published somewhere – If not, harass the vendor  30
  29. 29. 31
  30. 30. Methods • Actions taken upon a resource – GET – PUT – POST – DELETE – PATCH 32
  31. 31. Methods • Actions taken upon a resource – GET data from a resource – PUT to create resources – POST to update a resource – DELETE to remove a resource – PATCH to update parts of a resource 33
  32. 32. Authentication • Verify your identity – Basic auth (fairly common) – Oauth – Oauth2 34
  33. 33. Authentication • Did you know? – Basic auth uses Base64 encoding + SSL – Encoding = reversible – Thus, name and password are plain text • Encryption is provided by SSL – SSL is “optional” but … it really isn’t – Don’t call endpoints with HTTP! 35
  34. 34. Sample Basic Auth Code for PowerShell $auth = [System.Convert]::ToBase64String([System.Text.Encoding]: :UTF8.GetBytes($Username + “:” + $Password)) $header = @{“Authorization”=“Basic $auth”} 36
  35. 35. 37 Cmdlet Format / Usage
  36. 36. 38 Invoke-WebRequest ` -Uri something.urlvmlist ` -Method Get ` -Headers $header Cmdlet
  37. 37. 39 Invoke-WebRequest ` -Uri something.urlvmlist ` -Method Get ` -Headers $header Resource / Endpoint
  38. 38. 40 Invoke-WebRequest ` -Uri something.urlvmlist ` -Method Get ` -Headers $header Method
  39. 39. 41 Invoke-WebRequest ` -Uri something.urlvmlist ` -Method Get ` -Headers $headerAuthentication
  40. 40. 45
  41. 41. 46
  42. 42. 47 What can I do with this? Protecting Applications with Rubrik
  43. 43. 48 Imperative Declarative
  44. 44. 50 Policy{SLA
  45. 45. 51 Recovery Point Objective (RPO) Availability Duration (Retention) When to Archive (RTO) Replication Schedule (DR) {SLA
  46. 46. 52
  47. 47. Associate Policy to vSphere Objects 53 vCenter Server VM VM VM VM VM VM VM VM Silver SLA Gold SLA Bronze SLA
  48. 48. 54 End-to-End Data Management Primary Data Center DR Site/Offsite VM VM VM VM VM VM Hypervisor Production Servers SAN VM VM VM VM VM VM Hypervisor DR Servers Rubrik Backup Software + Dedupe Storage Rubrik Replication & DR Offsite + Long Term Archive
  49. 49. 55 Free Code as Examples
  50. 50. Community PowerShell Module GitHub PowerShell-Module Repository – https://github.com/rubrikinc/PowerShell-Module PowerShell Gallery (NuGet) – https://www.powershellgallery.com/packages/Rubrik – Install-Module -Name Rubrik 56
  51. 51. vRealize Orchestrator (vRO) Package GitHub vRO-Workflow Repository – https://github.com/rubrikinc/vRO-Workflow – Visit the Wiki for a full walkthrough! 57
  52. 52. Thank You @ChrisWahl chris.wahl@rubrik.com 58

×