Skip to content

Instantly share code, notes, and snippets.

@ErikHen
ErikHen / LoginToAzure
Created April 3, 2019 19:40
Azure Automation Powershell Runbook that logs in to Azure
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
using ImageProcessor.Web.Episerver;
namespace PictureDemo.Business.Rendering
{
public static class ImageTypes
{
// A full width Hero image is very simple, since its always 100% of the viewport width.
public static ImageType HeroImage = new ImageType
{
DefaultImgWidth = 1280,
using MyEpiSite.Business.Rendering;
using System;
using System.Configuration;
using System.Web;
using System.Web.Mvc;
namespace MyEpiSite.Helpers
{
public static class PictureHelper
{
namespace MyEpiSite.Business.Rendering
{
public class ImageType
{
public int? DefaultImgWidth { get; set; } //this size will be used in browsers that don't support the picture element
public int[] SrcSetWidths { get; set; } // the different image widths you want the browser to select from
public string[] SrcSetSizes { get; set; }
public double HeightRatio { get; set; }
public int Quality { get; set; }
namespace MyEpiSite.Business.Rendering
{
public class ImageType
{
public int? DefaultImgWidth { get; set; } //this size will be used in browsers that don't support the picture element
public int[] SrcSetWidths { get; set; } // the different image widths you want the browser to select from
public string[] SrcSetSizes { get; set; }
}
public static class ImageTypes
using MyEpiSite.Business.Rendering;
using System.Configuration;
using System.Web;
using System.Web.Mvc;
namespace MyEpiSite.Helpers
{
public static class PictureHelper
{
public static IHtmlString Picture(this HtmlHelper helper, string imageUrl, ImageType imageType, string cssClass = "")
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Linq;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;
using EPiServer.Web;
@ErikHen
ErikHen / NotifySlack.ps1
Last active November 22, 2017 21:07
PowerShell function that sends a message to Slack
function NotifySlack($webhookurl, $channel, $message)
{
$payload = @{
"channel" = $channel
"icon_emoji" = ":robot_face:"
"text" = $message
"username" = "Mr. Robot"
}
Invoke-WebRequest -UseBasicParsing -Body (ConvertTo-Json -Compress -InputObject $payload) -Method Post -Uri $webhookurl | Out-Null
}
Import-Module "D:\home\site\wwwroot\ScaleDownDevEnvironments\LoginToAzure.ps1"
Import-Module "D:\home\site\wwwroot\ScaleDownDevEnvironments\NotifySlack.ps1"
Login
#scale down web app to "D1 Shared"
Set-AzureRmAppServicePlan -Name "<your sesrvice plan name>" -ResourceGroupName "<your resource group name>" -Tier Shared
#scale down database to "B1 Basic"
Set-AzureRmSqlDatabase -ResourceGroupName "<your resource group name>" -ServerName "<sql server name>" -DatabaseName "<database name>" -Edition Basic
function Login() {
$azureappid ="45d6472e-0526-4a12-8c58-959f697eb296" #your Azure application id
$azurepassword = ConvertTo-SecureString "YourSecretPassword" -AsPlainText -Force
$pscred = New-Object System.Management.Automation.PSCredential($azureappid, $azurepassword)
Login-AzureRmAccount -Credential $pscred -ServicePrincipal -TenantId "31d2b6c6-a122-456c-b9a5-af2d7e3fbf0f" #you Azure subscription Tenant id
}