Starting migration to the Azure PowerShell Az module
- List all Storage Accounts
- Storage Account Details
- Create Storage Account
- Create Blob Container
- Upload File to Blob Container
- List Blobs in Container
- Download Blob
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
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
If more than one subscription is attached to your Azure Account you might need to change the subscription you are pointing at.
Get-AzContext
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]
Get-Module Az.* -ListAvailable | Sort-Object Version
In this example all commands in the module AzureRM.ServiceBus is retrieved
Get-Command -Module Az.ServiceBus
Get-AzResourceGroup | Select-Object ResourceGroupName, Location
get-azresource -ResourceGroupName $resourcegroup
New-AzResourceGroup -Name $resourcegroup -Location $location
Remove-AzResourceGroup -Name $resourcegroup -Force
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]
$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
}
}
}
$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
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
Get-AzStorageAccount
Get-AzStorageAccount -ResourceGroupName "[RESOURCE_GROUP]" -Name "[STORAGE_ACCOUNT]" | format-list -Property *
$storageAccount = New-AzStorageAccount -ResourceGroupName $resourcegroup -Name $storageName -Location $location -SkuName Standard_LRS -Kind StorageV2 -AccessTier Hot
$storageContext = $storageAccount.Context
New-AzStorageContainer -Name $blobContainerName -Context $storageContext
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
Get-AzStorageBlob -Container $blobContainerName -Context $storageContext
Get-AzStorageBlobContent -Blob $fileName -Container $blobContainerName -Context $storageContext -Destination C:\temp\fromazure.txt
Set-AzureRmLogicApp -ResourceGroupName "[RESOURCE_GROUP]" -Name "[STORAGE_ACCOUNT]" -State Enabled
$apicontext = New-AzureRmApiManagementContext -ResourceGroupName [Resource Group] -ServiceName [name of Service]
Get-AzureRmApiManagementApi -Context $apicontext
- 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?)
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
[{
"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"
[
{
"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"
}
]
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 :
New-AzEventGridSubscription -EventSubscriptionName CustomToRequstBin -Endpoint $endpoint -TopicName mycustomtopic -ResourceGroupName $resourcegroup
$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)