Code Monkey home page Code Monkey logo

azureazure's Introduction

Microsoft AZURE by Morten la Cour

Starting migration to the Azure PowerShell Az module

Table of Content

  1. Install PowerShell
  2. Starting PowerShell
  3. Changing Subscription
  4. Exploring PowerShell
  1. Create Resource Group
  2. Delete Resource Group
  1. List all Queues
  2. List all Topics
  3. Creating a subscription
  4. All from scratch
  1. List all Storage Accounts
  2. Storage Account Details
  3. Create Storage Account
  4. Create Blob Container
  5. Upload File to Blob Container
  6. List Blobs in Container
  7. Download Blob
  1. List all Logic Apps
  2. Enable a Logic App
  1. List API'S
  1. Create Standard Subscription
  2. Create a Custom Topic

PowerShell

Install Powershell

Run Powershell as Adminstrator

Make sure you are running at least Powershell version 5.0. Check this by running the following command

When using AZ instead of AzureRM Powershell version 6.* is recommended. Also .NET Framework 4.7.2 is required.

Check .NET Framework version

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\'

The Release number should be at least 461808

Check Powershell version

$PSVersionTable.PSVersion

Now install the AZ Powershell Module say Yes or Yes to All when prompted

Install-Module -Name Az -AllowClobber

Back to top

Starting Powershell

MIGHT BE OBSOLETE USING AZ??

This step needs to be done every time PowerShell is started. The import part, however, can be automated by setting up a PowerShell Profile

Import-Module AZ
Connect-AzAccount

You might need to set the following in order to be able to run Import-Module

Set-ExecutionPolicy RemoteSigned

Back to top

Changing Subscription

If more than one subscription is attached to your Azure Account you might need to change the subscription you are pointing at.

Check current subscription

Get-AzContext

List all subscriptions

Get-AzSubscription

If you need to change the subscription, get the Id from the list of subscriptions and use the following command

Select-AzSubscription -SubscriptionId [Id]

Back to top

Exploring PowerShell

Get a list of all available modules (Sort by version)

Get-Module Az.* -ListAvailable | Sort-Object Version

Get a list of commands

In this example all commands in the module AzureRM.ServiceBus is retrieved

Get-Command -Module Az.ServiceBus

Back to top

Resource Groups

List all Resource Groups

Get-AzResourceGroup | Select-Object ResourceGroupName, Location

List all Resources in a Resource Group

get-azresource -ResourceGroupName $resourcegroup

Create Resource Group

New-AzResourceGroup -Name $resourcegroup -Location $location

Delete Resource Group

Remove-AzResourceGroup -Name $resourcegroup -Force

Back to top

Service Bus

List all Queues

Get-AzureRmServiceBusNamespace -ResourceGroupName [resourceGroup] -Name [namespace] | select ResourceGroup, @{Name="Namespace";Expression={$_."Name"}} | Get-AzureRmServiceBusQueue | select Name

Note that piping in PowerShell can pass parameters through pipes. However in this case the namespace's Name needs to be mapped to Namespace in order to be passed to the Get-Queue Cmdlet.

The example above is only to show how to map parameters, the same can be accomplished by this:

Get-AzureRmServiceBusQueue -ResourceGroupName [resourceGroup] -Namespace [namespace]

Back to top

List all Topics

$rg = "MY_RESOURCE_GROUP"
$ns = "SERVICE_BUS_NAMESPACE"
$topics = Get-AzureRmServiceBusTopic -ResourceGroupName $rg -Namespace $ns
foreach($topic in $topics)
{
    Write-Host $topic.Name
    $subs = Get-AzureRmServiceBusSubscription -ResourceGroupName $rg -Namespace $ns -Topic $topic.Name
    foreach($sub in $subs)
    {
        Write-Host "`tSub:"  $sub.Name
        $filters = Get-AzureRmServiceBusRule -ResourceGroupName $rg -Namespace $ns -Topic $topic.Name -Subscription $sub.Name
        foreach($filter in $filters) 
        {
            Write-Host "`t`tFilter:" $filter.SqlFilter.SqlExpression
        }
    }
}

Back to top

Creating a Subscription

$rg = "MY_RESOURCE_GROUP"
$ns = "SERVICE_BUS_NAMESPACE"
$topic = "TOPIC_NAME"
$sub = "NAME_OF_NEW_SUBSCRIPTION"
$ruleName = "NAME_OF_NEW_RULE"
$filter = "(receiver = 'thereceiver')"

New-AzureRmServiceBusSubscription -ResourceGroupName $rg -Namespace $ns -Topic $topic -SubscriptionName $sub
New-AzureRmServiceBusRule -ResourceGroupName $rg -Namespace $ns -Topic $topic -Subscription $sub -SqlExpression $filter  -Name $ruleName

Back to top

All from scratch

Check to see if the SB-Namespace is available

Test-AzureRmServiceBusName -Namespace stupidnamespace

If the result NameAvailable is True, you can grab the globally unique namespace

Create the namespace

New-AzureRmServiceBusNamespace -ResourceGroupName [ResourceGroupName] -Name stupidnamespace -Location "West Europe"

Retrieve the connection-string

When created the namespace will only hold one Auth-Rule (RootManageSharedAccessKey) if others are created, all Auth-Rules can be listed here

Get-AzureRmServiceBusAuthorizationRule -ResourceGroupName [ResourceGroupName] -Namespace stupidnamespace

Now get the connection-string from the rule (Replace RootManageSharedAccessKey if you wish to use another rule)

Get-AzureRmServiceBusKey -ResourceGroupName MLC_Temp -Namespace stupidnamespace -Name RootManageSharedAccessKey | select PrimaryConnectionString

The last pipe is optional, it just gives us the ability to better see the PrimaryConnectionString

Create a new queue with Duplicate Detection enabled

New-AzureRmServiceBusQueue -ResourceGroupName [ResourceGroupName] -Namespace stupidnamespace -Name messagein -RequiresDuplicateDetection $True

Back to top

Storage

List all Storage Accounts

Get-AzStorageAccount

Back to top

Storage Account Details

Get-AzStorageAccount -ResourceGroupName "[RESOURCE_GROUP]" -Name "[STORAGE_ACCOUNT]" | format-list -Property *

Create Storage Account

$storageAccount = New-AzStorageAccount -ResourceGroupName $resourcegroup -Name $storageName -Location $location -SkuName Standard_LRS -Kind StorageV2 -AccessTier Hot

$storageContext = $storageAccount.Context

Create Blob Container

New-AzStorageContainer -Name $blobContainerName -Context $storageContext

Upload File to Blob Container

If you need a test file

New-Item -Path $filePath -Name $fileName -Type File -Value "This is the content"
Set-AzStorageBlobContent -File "$filePath\$fileName" -Container $blobContainerName -Context $storageContext -Blob $fileName

List Blobs in Container

Get-AzStorageBlob -Container $blobContainerName -Context $storageContext

Download Blob

Get-AzStorageBlobContent -Blob $fileName -Container $blobContainerName -Context $storageContext -Destination C:\temp\fromazure.txt

Back to top

Logic Apps

List of all Logic Apps

Back to top

Enable a Logic App

Set-AzureRmLogicApp -ResourceGroupName "[RESOURCE_GROUP]" -Name "[STORAGE_ACCOUNT]" -State Enabled

Back to top

API Management

List APIS

$apicontext = New-AzureRmApiManagementContext -ResourceGroupName [Resource Group] -ServiceName [name of Service]
Get-AzureRmApiManagementApi -Context $apicontext

Back to top

Azure On-premises Data Gateway

Install the gateway on an on-prem Server

  • Download the GatewayInstall.exe from the following address https://aka.ms/azureasgateway
  • Install and configure, follow the instructions
  • You should now have a Windows Service named Microsoft.PowerBI.EnterpriseGateway.exe running
  • Configure an On-premises Data Gateway in Azure, signing in with the same name as used when configuring the on-prem service

(some Location restriction may be required. I had to change from West Europe to North Europe before anything showed up in the Installation Name dropdown?)

Back to top

Event Grid

Create Standard Subscription

New-AzEventGridSubscription -EventSubscriptionName storageToRequestBin -ResourceId $storageId -Endpoint $endpoint

$endpoint is a WebHook endpoint. https://en3jyjvadsa46.x.pipedream.net/

$storageId (ResourceId) is the address for (for instance) the Storage Id /subscriptions/4954f2df-57b6-4e04-bcc5-f92b0b63837c/resourceGroups/sandbox/providers/Microsoft.Storage/storageAccounts/sandstorage

NOTE: If you are using just an HTTP endpoint and not a true WebHook you will receive a validationUrl that you manually needs to call with a GET Method

Validation data sent to Endpoint

[{
  "id": "755980c4-8571-4ac5-bf53-2108a33e4445",
  "topic": "/subscriptions/4954f2df-57b6-4e04-bcc5-f92b0b63837c/resourceGroups/sandbox/providers/microsoft.storage/storageaccounts/sandstorage",
  "subject": "",
  "data": {
    "validationCode": "9F0C5719-2B8B-4DAF-9C36-F5FD3B5C8B7C",
    "validationUrl": "https://rp-westeurope.eventgrid.azure.net/eventsubscriptions/storagetorequestbin/validate?id=9F0C5719-2B8B-4DAF-9C36-F5FD3B5C8B7C&t=2019-02-16T15:52:05.6430791Z&apiVersion=2019-01-01&token=3LYXtMkeUxlpMNwBcD2NcSkgZdgvHnXKB8HwBqElU5U%3d"
  },
  "eventType": "Microsoft.EventGrid.SubscriptionValidationEvent",
  "eventTime": "2019-02-16T15:52:05.6430791Z",
  "metadataVersion": "1",
  "dataVersion": "2"
}]

When calling the validationUrl you should see the following message (note the spelling error, NICE MS!!) "Webhook succesfully validated as a subscription endpoint"

Data when a Blob is Created

[
    {
        "topic": "/subscriptions/4954f2df-57b6-4e04-bcc5-f92b0b63837c/resourceGroups/sandbox/providers/Microsoft.Storage/storageAccounts/sandstorage",
        "subject": "/blobServices/default/containers/demo/blobs/order.edi",
        "eventType": "Microsoft.Storage.BlobCreated",
        "eventTime": "2019-02-16T16:01:27.9973176Z",
        "id": "f59b3322-f01e-0151-4010-c6e9ab0610ef",
        "data": {
            "api": "PutBlob",
            "clientRequestId": "Azure-Storage-PowerShell-982add45-4b77-40ec-bc9e-03398aaa5a9d",
            "requestId": "f59b3322-f01e-0151-4010-c6e9ab000000",
            "eTag": "0x8D69428026F6C1F",
            "contentType": "application/octet-stream",
            "contentLength": 550,
            "blobType": "BlockBlob",
            "url": "https://sandstorage.blob.core.windows.net/demo/order.edi",
            "sequencer": "000000000000000000000000000005C3000000000017880a",
            "storageDiagnostics": {
                "batchId": "7ed4da80-fb56-46dd-833e-d0202a9a3753"
            }
        },
        "dataVersion": "",
        "metadataVersion": "1"
    }
]

Create a Custom Topic

New-AzEventGridTopic -ResourceGroupName $resourcegroup -Location $location -Name mycustomtopic

ResourceGroupName : sandbox
TopicName         : mycustomtopic
Id                : /subscriptions/4954f2df-57b6-4e04-bcc5-f92b0b63837c/resourceGroups/sandbox/providers/Microsoft.EventGrid/topics/mycustomtopic
Type              : Microsoft.EventGrid/topics
Location          : westeurope
Endpoint          : https://mycustomtopic.westeurope-1.eventgrid.azure.net/api/events
ProvisioningState : Succeeded
Tags              :

Subscribe to the custom Topic

New-AzEventGridSubscription -EventSubscriptionName CustomToRequstBin -Endpoint $endpoint -TopicName mycustomtopic -ResourceGroupName $resourcegroup

Submit to Custom Topic

$topicendpoint = (Get-AzEventGridTopic -ResourceGroupName $resourcegroup -Name mycustomtopic).Endpoint
$topickeys = Get-AzEventGridTopicKey -ResourceGroupName $resourcegroup -Name mycustomtopic

Set Request Header: aeg-sas-key : $topickeys.Key1

Minimum body

[{
	"id" : "1807",
	"subject" : "myapp/Morten",
	"eventType" : "Something",
	"eventTime" : "2019-01-01"
}]

HTTP POST: $topicendpoint

$topicendpoint (https://mycustomtopic.westeurope-1.eventgrid.azure.net/api/events)

Back to top

azureazure's People

Contributors

xemmel avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.