Start-Stop-Automation/Automation-Backend/Runbooks/Tag-SAPStandaloneSQLServer.ps1 (66 lines of code) (raw):

<#PSScriptInfo .DESCRIPTION Azure Automation runbook script to tag an standalone SAP SQl Server DB VM. .VERSION 0.0.2 .GUID 760d4a23-5a1c-4768-a8bd-2dd669ec15ed .AUTHOR Goran Condric .COMPANYNAME Microsoft .COPYRIGHT (c) 2020 Microsoft . All rights reserved. .TAGS Azure Automation SAP SQl Server Tag Standalone DB Runbook .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES SAPAzurePowerShellModules .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES 0.0.1: - Add initial version 0.0.2: - Add dedpendencies to SAPAzurePowerShellModules module #> #Requires -Module SAPAzurePowerShellModules Param( [Parameter(Mandatory=$True)] [ValidateNotNullOrEmpty()] [string] $ResourceGroupName, [Parameter(Mandatory=$True)] [ValidateNotNullOrEmpty()] [string] $VMName, [Parameter(Mandatory=$True, HelpMessage="SAP System <SID>. 3 characters , starts with letter.")] [ValidateLength(3,3)] [string] $SAPSID, [Parameter(Mandatory=$false, HelpMessage="SQL Server DB Instance Name. Empty string is deafult SQL instance name.")] [string] $DBInstanceName = "", [Parameter(Mandatory=$false, HelpMessage="Subscription ID. If null, the current subscription of automation account is used instead.")] [ValidateLength(36,36)] [string] $SubscriptionId ) # Deprecated due to using System Managed Identity #$connection = Get-AutomationConnection -Name AzureRunAsConnection #Add-AzAccount -ServicePrincipal -Tenant $connection.TenantID -ApplicationId $connection.ApplicationID -CertificateThumbprint $connection.CertificateThumbprint # Connect to Azure with Automation Account system-assigned managed identity # Ensure that you do not inherit an AZ Context in your runbook Disable-AzContextAutosave -Scope Process | out-null # Connect using Managed Service Identity try { $AzureContext = (Connect-AzAccount -Identity -WarningAction Ignore).context } catch{ Write-Output "There is no system-assigned user identity. Aborting."; Write-Error $_.Exception.Message exit } if ($SubscriptionId){ $SubscriptionId = $SubscriptionId.trim() Select-AzSubscription -SubscriptionId $SubscriptionId -ErrorVariable -notPresent -ErrorAction SilentlyContinue -Tenant $AzureContext.Tenant } $ResourceGroupName = $ResourceGroupName.Trim() $VMName = $VMName.Trim() $SAPSID = $SAPSID.Trim() $DBInstanceName = $DBInstanceName.Trim() # Check if resource group exists. If $False exit Confirm-AzResoureceGroupExist -ResourceGroupName $ResourceGroupName # Check if VM. If $False exit Confirm-AzVMExist -ResourceGroupName $ResourceGroupName -VMName $VMName # Tag standalone SAP HANA on ONE VM New-AzSAPStandaloneSQLServerTags -ResourceGroupName $ResourceGroupName -VMName $VMName -SAPSID $SAPSID -DBInstanceName $DBInstanceName Write-WithTime "Standalone SAP SQL Server use case. Distributed SAP installation." Write-WithTime "Tagging of VM '$VMName' in resource group '$ResourceGroupName' with tags: SAPSID='$SAPSID'; SAPDBMSType='SQLServer' ; DBInstanceName='$DBInstanceName' done."