Skip to content

Instantly share code, notes, and snippets.

@jmrynning
jmrynning / AuthAzure.ps1
Created October 9, 2018 05:27
Get Azure access token for running REST API
$azContext = Get-AzureRmContext
$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azProfile)
$token = $profileClient.AcquireAccessToken($azContext.Subscription.TenantId)
$authHeader = @{
'Content-Type'='application/json'
'Authorization'='Bearer ' + $token.AccessToken
}
# Invoke the REST API
@jmrynning
jmrynning / enableHttpsOnly.ps1
Last active October 9, 2018 05:28
Enable HTTPS Only on Azure Web App
# Get Web App Data
$AppService = Get-AzureRmWebApp -Name "WebAppName" -ResourceGroupName "ResourceGroupName"
# Get Resource
$AppResource = Get-AzureRmResource -ResourceId $AppService.Id
# Force use of HTTPS only
$Properties = @{httpsOnly = $true}
# Commit changes
Set-AzureRmResource -ResourceName $AppResource.Name -ResourceGroupName $AppResource.ResourceGroupName -Properties $Properties -ResourceType "Microsoft.Web/sites" -Force