Advertisement
Guest User

Untitled

a guest
Sep 11th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <#
  2. .SYNOPSIS
  3. ExecWebJob
  4.  
  5. .DESCRIPTION
  6.  
  7. .parameter $CredInfo
  8. Credential Name
  9.  
  10. .parameter $UriInfo
  11. webjob's URL
  12.  
  13. .EXAMPLE
  14. ExecWebjob -CredInfo "hoge" -UriInfo "hoge"
  15.  
  16. .NOTES
  17. AUTHOR: wantashi
  18. LASTEDIT: 2017/08/15
  19. #>
  20. param(
  21. [parameter(Mandatory=$True)]
  22. [string] $CredInfo,
  23.  
  24. [parameter(Mandatory=$True)]
  25. [string] $Uri
  26. )
  27.  
  28. # GetUri
  29. #$uri = Get-AutomationVariable -Name $UriInfo
  30.  
  31. # GetCredential
  32. $myCredential = Get-AutomationPSCredential -Name $CredInfo
  33.  
  34.  
  35. # build String of Basic Authentication
  36. $user = $myCredential.UserName
  37. $pass = $myCredential.GetNetworkCredential().Password
  38. $pair = "${user}:${pass}"
  39. $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(($pair)))
  40. $header = @{ Authorization=("Basic {0}" -f $base64AuthInfo) }
  41.  
  42. # Exec webjob
  43. Invoke-RestMethod -Method post -Uri $Uri -ContentType "application/json" -Headers $header
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement