Created
December 15, 2015 20:14
-
-
Save bgelens/88e1ea12f3467d31dfcd to your computer and use it in GitHub Desktop.
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
$adal = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll" | |
$adalforms = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll" | |
[System.Reflection.Assembly]::LoadFrom($adal) | |
[System.Reflection.Assembly]::LoadFrom($adalforms) | |
$adTenant = 'bla.onmicrosoft.com' | |
$subscriptionid = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' | |
$jobname = 'MyJob' | |
$collection = 'MyCollection' | |
$location = 'westeurope' | |
$clientId = '1950a258-227b-4e31-a9cf-717495945fc2' | |
$redirectUri = 'urn:ietf:wg:oauth:2.0:oob' | |
$resourceAppIdURI = 'https://management.core.windows.net/' | |
$authority = "https://login.windows.net/$adTenant" | |
$authContext = New-Object -TypeName 'Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext' -ArgumentList $authority | |
$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, 'Auto') | |
$authHeader = $authResult.CreateAuthorizationHeader() | |
$WebHookToken = '' | |
$schedulerURI = 'https://management.core.windows.net/{0}/cloudservices/cs-{1}-scheduler/resources/scheduler/~/JobCollections/{2}/jobs/{3}?api-version=2014-04-01' -f $subscriptionid,$location,$collection,$jobname | |
$body = '{ | |
"action": | |
{ | |
"type": "https", | |
"request": | |
{ | |
"uri": "https://s2events.azure-automation.net/webhooks?token={0}", | |
"method": "POST", | |
"headers": | |
{ | |
"Content-Type": "text/plain" | |
} | |
} | |
}, | |
"recurrence": | |
{ | |
"Frequency": "Week", | |
"interval": 1, | |
"schedule": | |
{ | |
"minutes":[15,30,45], | |
"hours": [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22], | |
"weekDays":["Monday","Tuesday","Wednesday","Thursday","Friday"] | |
} | |
}, | |
"state": "enabled" | |
}' -f $WebHookToken | |
$headers = @{ | |
'x-ms-version' = '2013-08-01' | |
'Content-type' = 'application/json' | |
'Authorization' = $authHeader | |
} | |
$output = Invoke-RestMethod -Uri $schedulerURI -Method Put -Body $body -Headers $headers | |
$output | |
$GetJob = Invoke-RestMethod -Uri $schedulerURI -Method Get -Headers $headers | |
$GetJob |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment