← Back to Blog

Get an enviroment that can run 7.2 for the automation to work with keys for a Logic App run on Azure Automation

Get an enviroment that can run 7.2 for the automation to work with keys for a Logic App run on Azure Automation Goal : to have the azure automation run on its own Azure automation has the 7.2 Can i test in the cli azure? cloud shell and powershell runtime would they match ?

Get an enviroment that can run 7.2 for the automation to work with keys for a Logic App run on Azure Automation

Goal : to have the azure automation run on its own

Azure automation has the 7.2

Can i test in the cli azure?

get an enviroment 1

cloud shell and powershell runtime would they match ?

get an enviroment 2

7.4 could overlap with 7.2?

get an enviroment 3

maybe my main error was the popup error and the basics are not covered in scripting tools

get an enviroment 4

Silent olmasi onemli

get an enviroment 5

All lines did not work

get an enviroment 6

error at fist line

Connect-AzAccount -UseDeviceAuthentication

$rsg = 'ContractorMarketing'

$storageid = '/subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Storage/storageAccounts/contractormarketing'

$diagname = 'mydiagnostics'

$resourceid = '/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport'

Set-AzDiagnosticSetting -Name $diagname -ResourceId $resourceid -StorageAccountId $storageid -Enabled $true -Categories CoreAnalytics

find the new functions

get an enviroment 7

https://learn.microsoft.com/en-us/powershell/module/az.monitor/new-azdiagnosticsetting?view=azps-11.3.0&viewFallbackFrom=azps-9.7.1

different type of creation

get an enviroment 8

New-AzDiagnosticSetting -Name mydiag -setting -ResourceId /subscriptions/$subscriptionId/resourceGroups/test-rg-name/providers/Microsoft.AppPlatform/Spring/springcloud-001 -WorkspaceId /subscriptions/$subscriptionId/resourcegroups/test-rg-name/providers/microsoft.operationalinsights/workspaces/test-workspace -Log $log -Metric $metric

Practical grab the resource id

get an enviroment 9

/subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport

New-AzDiagnosticSetting -Name mydiag -setting -ResourceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport -WorkspaceId /subscriptions/$subscriptionId/resourcegroups/test-rg-name/providers/microsoft.operationalinsights/workspaces/test-workspace -Log $log -Metric $metric

workspaceid simil.ar grab

get an enviroment 10

/subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourcegroups/contractormarketing/providers/microsoft.operationalinsights/workspaces/contractormarketing-loganalytics

New-AzDiagnosticSetting -Name mydiag -setting -ResourceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport -WorkspaceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourcegroups/contractormarketing/providers/microsoft.operationalinsights/workspaces/contractormarketing-loganalytics -Log $log -Metric $metric

All Code

$subscriptionId = (Get-AzContext).Subscription.Id $metric = @() $log = @() $metric += New-AzDiagnosticSettingMetricSettingsObject -Enabled $true -Category AllMetrics -RetentionPolicyDay 7 -RetentionPolicyEnabled $true $log += New-AzDiagnosticSettingLogSettingsObject -Enabled $true -Category ContainerEventLogs -RetentionPolicyDay 7 -RetentionPolicyEnabled $true New-AzDiagnosticSetting -Name mydiag -ResourceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport -WorkspaceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourcegroups/contractormarketing/providers/microsoft.operationalinsights/workspaces/contractormarketing-loganalytics -Log $log -Metric $metric

get an enviroment 11

$log += New-AzDiagnosticSettingLogSettingsObject -Enabled $true -Category ContainerEventLogs -RetentionPolicyDay 7 -RetentionPolicyEnabled $true
$log += New-AzDiagnosticSettingLogSettingsObject -Enabled $true -RetentionPolicyDay 7 -RetentionPolicyEnabled $true

category error > switch to all

$categories = Get-AzDiagnosticSettingCategory -ResourceId /subscriptions/$subscriptionId/resourceGroups/test-rg-name/providers/Microsoft.AppPlatform/Spring/springcloud-001

$categories = Get-AzDiagnosticSettingCategory -ResourceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport

$categories | ForEach-Object {if($.CategoryType -eq "Metrics"){$metric+=New-AzDiagnosticSettingMetricSettingsObject -Enabled $true -Category $.Name -RetentionPolicyDay 7 -RetentionPolicyEnabled $true} else{$log+=New-AzDiagnosticSettingLogSettingsObject -Enabled $true -Category $_.Name -RetentionPolicyDay 7 -RetentionPolicyEnabled $true}}

New-AzDiagnosticSetting -Name test-setting -ResourceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport -WorkspaceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourcegroups/contractormarketing/providers/microsoft.operationalinsights/workspaces/contractormarketing-loganalytics -Log $log -Metric $metric

still missing

get an enviroment 12

bigger screen needed

runner ps1

get an enviroment 13

bigger action can be run

get an enviroment 14

Longer script testing is there

get an enviroment 15

cloud runner took time

get an enviroment 16

$subscriptionId = (Get-AzContext).Subscription.Id

$metric = @()

$log = @()

$categories = Get-AzDiagnosticSettingCategory -ResourceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport

$categories | ForEach-Object {if($.CategoryType -eq "Metrics"){$metric+=New-AzDiagnosticSettingMetricSettingsObject -Enabled $true -Category $.Name} else{$log+=New-AzDiagnosticSettingLogSettingsObject -Enabled $true -Category $_.Name}}

New-AzDiagnosticSetting -Name test-setting -ResourceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport -WorkspaceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourcegroups/contractormarketing/providers/microsoft.operationalinsights/workspaces/contractormarketing-loganalytics -Log $log -Metric $metric

Missing settings

get an enviroment 17

arm id

get an enviroment 18

too many settings

get an enviroment 19

$subscriptionId = (Get-AzContext).Subscription.Id

$metric = @()

$log = @()

$categories = Get-AzDiagnosticSettingCategory -ResourceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport

$categories | ForEach-Object {if($.CategoryType -eq "Metrics"){$metric+=New-AzDiagnosticSettingMetricSettingsObject -Enabled $true -Category $.Name} else{$log+=New-AzDiagnosticSettingLogSettingsObject -Enabled $true -Category $_.Name}}

New-AzDiagnosticSetting -Name test-setting3 -EventHubAuthorizationRuleId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourcegroups/ContractorMarketing/providers/Microsoft.EventHub/namespaces/contractormarketing/authorizationrules/RootManageSharedAccessKey -EventHubName contractormarketing-logicapp -StorageAccountId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Storage/storageAccounts/contractormarketing -ResourceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport -WorkspaceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourcegroups/contractormarketing/providers/microsoft.operationalinsights/workspaces/contractormarketing-loganalytics -Log $log -Metric $metric

get an enviroment 20

other than alllogs selected

get an enviroment 21

go with what you can

get an enviroment 22

still cant run something new?

get an enviroment 23

get an enviroment 24

republish to overwrite and rerun

get an enviroment 25

better errors

get an enviroment 26

maybe i connect it

get an enviroment 27

added to the top

get an enviroment 28

at least i can see the runs

get an enviroment 29

much longer runtime

get an enviroment 30

automation run has issues

get an enviroment 31

the connections it has

get an enviroment 32

Add Connection

get an enviroment 33

get an enviroment 34

here we need a cert

https://github.com/Huachao/azure-content/blob/master/articles/automation/automation-certificates.md

this one can not create it

get an enviroment 35

Open cloud shell to try it

get an enviroment 36

tenant selection

get an enviroment 37

get an enviroment 38

based on a resource group as well

Create the automation account and delete it

get an enviroment 39

certificate uploader should have rights to the folder

get an enviroment 40

Longer time to create

get an enviroment 41

$certName = 'MyCertificate'
$certPath = '.\MyCert.pfx'
$certPwd = ConvertTo-SecureString -String 'YY.....' -AsPlainText -Force

New-AzureAutomationCertificate -AutomationAccountName "MyAutomationAccount" -Name $certName -Path $certPath –Password $certPwd -Exportable

in 5 i am in

get an enviroment 42

again the same error

get an enviroment 43

install Az.Automation

get an enviroment 44

correct one gets installed by ease

get an enviroment 45

can not create it in the cloud as well

get an enviroment 46

Feels like a none connetion error

get an enviroment 47

First principles

get an enviroment 48

Creating the pfx file also did not work

get an enviroment 49

maybe a valid one has to be there

get an enviroment 50

creating your certificate file

https://www.advancedinstaller.com/what-is-pfx-certificate.html

get an enviroment 51

Read from scratch

https://endjin.com/blog/2015/02/generating-and-using-a-certificate-to-authorise-azure-automation

get an enviroment 52

certificate creation

get an enviroment 53

There is also changes in the back for the security

get an enviroment 54

Dev kit

get an enviroment 55

good packing with problem solution fit

get an enviroment 56

https://endjin.com/blog/2015/02/generating-and-using-a-certificate-to-authorise-azure-automation

powershell did not work

get an enviroment 57

google might not be the great answer check gpt

get an enviroment 58

get an enviroment 59

get an enviroment 60

difference it is Azure SDK

https://azure.github.io/azure-sdk/releases/latest/dotnet.html

get an enviroment 61

feels most modern

get an enviroment 62

https://learn.microsoft.com/en-gb/dotnet/api/overview/azure/security.keyvault.certificates-readme?view=azure-dotnet

have a keyvault

get an enviroment 63

get an enviroment 64

now there is create and chat option

get an enviroment 65

this could be promising > during the day

get an enviroment 66

I do not wanna use a VM to create a key where i forget it on

I am deleting it.

get an enviroment 67

Deleted it > if i can create the certificate in the cloud shell that works

get an enviroment 68

get an enviroment 69

Active tickets to be there to be in the handson action > leverage the support

get an enviroment 70

Chat is the new support type microsoft working in the background all the time

get an enviroment 71

someone tried it

https://techcommunity.microsoft.com/t5/itops-talk-blog/how-to-create-a-self-signed-certificate-in-azure-using-cloud/ba-p/401403

reality it would always fail and you got to be in the state of always fixing it

get an enviroment 72

2019 and looks like it works

get an enviroment 73

Similar testing with the gpt so the search and the gpt has to be mixed

get an enviroment 74

from none structured world to a structured one

try to go over the gpt

get an enviroment 75

Created a cert as pem

get an enviroment 76

private key and certificate packed together

get an enviroment 77

get an enviroment 78

Shared resources lets do it

get an enviroment 79

First try it with lastpass

get an enviroment 80

Privacy Enhanced Mail (PEM) files are a type of Public Key Infrastructure (PKI) file used for keys and certificates. PEM, initially invented to make e-mail secure, is now an Internet security standard.

Certificate here

get an enviroment 81

type different

get an enviroment 82

get an enviroment 83

https://stackoverflow.com/questions/13732826/convert-pem-to-crt-and-key

PS /home/rifat> openssl x509 -outform der -in mycert.pem -out mycert.crt
PS /home/rifat> ls
Microsoft mycert.crt mycert.pem
PS /home/rifat>

CRT format is different

get an enviroment 84

different

get an enviroment 85

get an enviroment 86

p12 file is also different

get an enviroment 87

without a tool

get an enviroment 88

Practical file download is there

get an enviroment 89

get an enviroment 90

ending has an issue

get an enviroment 91

Explain how i did it here

get an enviroment 92

Created the link ?

get an enviroment 93

There are rules

get an enviroment 94

Online creation is there as well

get an enviroment 95

get an enviroment 96

You need the rights to be able to import?

get an enviroment 97

fails

get an enviroment 98

Service principal could be easier

PS /home/rifat> az ad sp create-for-rbac --name myServicePrincipalName --role reader --scopes /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing

info created by itself and shared once

get an enviroment 99

at least saved

get an enviroment 100

Service principal creation is practical >> as it gives the info

a minute to run so that is not a big deal and service principal created by Azure cloud shell easier >>> no files management just paste into last pass

get an enviroment 101

No certificate was found in the certificate store with thumbprint

maybe thumbprint is taken from AD

get an enviroment 102

not there but hidden

get an enviroment 103

$CustomKeyIdentifier = (Get-AzureADApplicationKeyCredential -ObjectId "").CustomKeyIdentifier
$Thumbprint = [System.Convert]::ToBase64String($CustomKeyIdentifier)

maybe i need it before adding the cert it wont work

get an enviroment 104

pem file added to the user >>> so there is maybe 2 level

1.level create the user >>> have one username and pass

2.level have a certificate that means that is your user. which has the certificate and private key in it.

powershell has so many modules to work right have the system working

get an enviroment 105

script runners have hard time

get an enviroment 106

thumprint is here

https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/~/Credentials/appId/26b349e7-9736-4f6b-8b94-1352738efb14

added to the last pass

get an enviroment 107

now after the certiciate only one error is there

get an enviroment 108

owner or role adding ?

get an enviroment 109

New-AzDiagnosticSetting_CreateExpanded: Line | 15 | New-AzDiagnosticSetting -Name test-setting3 -EventHubAuthorizationRul … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | The client 'b23ced15-6bff-4a99-b8d0-7350f9e61f3b' with object id 'b23ced15-6bff-4a99-b8d0-7350f9e61f3b' does not have authorization to perform action 'Microsoft.Insights/diagnosticSettings/write' over scope '/subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport/providers/Microsoft.Insights/diagnosticSettings/test-setting3' or the scope is invalid. If access was recently granted, please refresh your credentials.

Just a reader >

get an enviroment 110

Make it a contributor and an owner

get an enviroment 111

THEY ARE BOTH IN

get an enviroment 112

detail of key creation >>> 2 way action

1) i created service principal ( json ) >> cloud shell

2)create the pem key >>> clould shelll

3) convert the pem to crt file

4)uploaded the crt to certificated of the serviceprincipal (got thumbprint )

5)created a connection in automation account with serviceprincal ( used thumbprint )

6)added the code to the automation using the connection

Waited in the queue and rerun

get an enviroment 113

`$Conn = Get-AutomationConnection -Name "serviceprincipal"
Connect-AzAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint

$subscriptionId = $Conn.Subscription.Id

$metric = @()

$log = @()

$categories = Get-AzDiagnosticSettingCategory -ResourceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport

$categories | ForEach-Object {if($.CategoryType -eq "Metrics"){$metric+=New-AzDiagnosticSettingMetricSettingsObject -Enabled $true -Category $.Name} else{$log+=New-AzDiagnosticSettingLogSettingsObject -Enabled $true -Category $_.Name}}

New-AzDiagnosticSetting -Name test-setting3 -EventHubAuthorizationRuleId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourcegroups/ContractorMarketing/providers/Microsoft.EventHub/namespaces/contractormarketing/authorizationrules/RootManageSharedAccessKey -EventHubName contractormarketing-logicapp -StorageAccountId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Storage/storageAccounts/contractormarketing -ResourceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/contractormarketing-schedule-dailyreport -WorkspaceId /subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourcegroups/contractormarketing/providers/microsoft.operationalinsights/workspaces/contractormarketing-loganalytics -Log $log -Metric $metric`

first time it is getting connected

get an enviroment 114

so much hassle for this

get an enviroment 115

$Conn = Get-AutomationConnection -Name "serviceprincipal"
Connect-AzAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint

Connection works >>> as it has it all and the password is protected over the certificate as we know the thumbprint for the cert

Created this know we need to take in a parameter and run this 46 times and in future diagnogistics that we need and be able to debug our serverless applications

get an enviroment 116

There are also other run books there

get an enviroment 117

top line is powershell added

get an enviroment 118

TODOS

todo 1 app paramaters

todo2 add this to the logic app

todo3 trigger the logic app create 46 configs

get an enviroment 119

Check if created

get an enviroment 120

Basic

get an enviroment 121

terminate and test a limited scope

get an enviroment 122

get an enviroment 123

Parameter landing

get an enviroment 124

Todos

todo 1 app paramaters ( inprogress )

todo2 add this to the logic app ( inprogress )

todo3 trigger the logic app create 46 configs ( )

Job ID is the output

get an enviroment 125

3 minute to run to much to debug

get an enviroment 126

So many queued at the same time

get an enviroment 127

Starting all at the same time

get an enviroment 128

it is not here

get an enviroment 129

Line 16 error

get an enviroment 130

46 errors piled up

get an enviroment 131

Get-AzDiagnosticSettingCategory_List: Line | 16 | $categories = Get-AzDiagnosticSettingCategory -ResourceId $myresource … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | The Resource 'Microsoft.Logic/workflows/providers' under resource group 'ContractorMarketing' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix

param looks empty?

get an enviroment 132

snapshot write is not there

get an enviroment 133

this time the snapshot as published with latest updates

get an enviroment 134

Basic string error is there

https://lazyadmin.nl/powershell/concatenate-string

test basics on cloud shell

get an enviroment 135

param1 incoming

get an enviroment 136

remove all extras to find where is the error

get an enviroment 137

simplier code

get an enviroment 138

stubbing

get an enviroment 139

meybe better parameters needed

get an enviroment 140

Json reading is different than string reading

get an enviroment 141

Json and string are not the same just the semblance

get an enviroment 142

other errors

get an enviroment 143

get an enviroment 144

get an enviroment 145

https://stackoverflow.com/questions/1315140/powershell-2-0-and-the-term-param-is-not-recognized-as-the-name-of-a-cmdlet

Json

get an enviroment 146

Json valid

get an enviroment 147

webui fails

get an enviroment 148

Saved code

"Please have the serviceprincipal with the certificate and give the resource group the access needed. Otherwise, the runbook may fail..."

Param(

[object]$json

)

"parameter is send to the json"

$json = $json | ConvertFrom-Json

"parameter read into json"

$param1 = $json.param1

"param1 assigned"

$Conn = Get-AutomationConnection -Name "serviceprincipal"

"connection created"

Connect-AzAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint

"connection established"

$subscriptionId = $Conn.Subscription.Id

$metric = @()

$log = @()

$myresourceid = "/subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Logic/workflows/"+$param1

"category load started"

$categories = Get-AzDiagnosticSettingCategory -ResourceId $myresourceid

$categories | ForEach-Object {if($.CategoryType -eq "Metrics"){$metric+=New-AzDiagnosticSettingMetricSettingsObject -Enabled $true -Category $.Name} else{$log+=New-AzDiagnosticSettingLogSettingsObject -Enabled $true -Category $_.Name}}

"category load ended"

$mydiagname = "mydiagsetting"

$workspaceid = "/subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourcegroups/contractormarketing/providers/microsoft.operationalinsights/workspaces/contractormarketing-loganalytics"

$ruleid = "/subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourcegroups/ContractorMarketing/providers/Microsoft.EventHub/namespaces/contractormarketing/authorizationrules/RootManageSharedAccessKey"

$storageaccountid = "/subscriptions/ad744a08-2411-4d78-b417-1f1c83f4f741/resourceGroups/ContractorMarketing/providers/Microsoft.Storage/storageAccounts/contractormarketing"

"diag started"

New-AzDiagnosticSetting -Name $mydiagname -EventHubAuthorizationRuleId $ruleid -EventHubName contractormarketing-logicapp -StorageAccountId $storageaccountid -ResourceId $myresourceid -WorkspaceId $workspaceid -Log $log -Metric $metric

"diag ended"

json is null

get an enviroment 149

saved json one more time

get an enviroment 150

for the first time it says JSON

get an enviroment 151

line 8

get an enviroment 152

it worked with an error?

get an enviroment 153

get an enviroment 154

there could be this kind of errors

get an enviroment 155

Event hub Started working

get an enviroment 156

in the favorites now

get an enviroment 157

get an enviroment 158

References

https://learn.microsoft.com/en-us/cli/azure/azure-cli-sp-tutorial-7?tabs=bash


Imported from rifaterdemsahin.com · 2024