# PS C:\> . .\CreateAzAutomationRunAsAccount.ps1 -ResourceGroup '<ResourceGroupName>' -Location '<AzureRegion>' -AutomationAccountName '<AutomationAccountName>' -ApplicationDisplayName '<AzureADApplicationName>' -SubscriptionId '<VSSubscriptionID>' -SelfSignedCertPlainPasswd '<SomeStrongPassword>' -SelfSignedCertNoOfMonthsUntilExpired 12 # To run the script you must pass parameters # -ResourceGroup, name of the Resource Group to create # -Location, Azure region to create Resource Group in, to get a list of available regions use Get-AzLocation # -AutomationAccountName, name of Automation Account to create # -ApplicationDisplayName, name of Azure AD application to create # -SubscriptionId, the Subscription ID of your Visual Studio subscription # -SelfSignedCertPlainPasswd, a strong password for the self-signed certificate # -SelfSignedCertNoOfMonthsUntilExpired, the number of months the self-signed certificate is valid, this is optional and if not passed this will default to 12 months. #Requires -RunAsAdministrator Param ( [Parameter(Mandatory = $true)] [string] $ResourceGroup, [Parameter(Mandatory = $true)] [string] $Location, [Parameter(Mandatory = $true)] [string] $AutomationAccountName, [Parameter(Mandatory = $true)] [string] $ApplicationDisplayName, [Parameter(Mandatory = $true)] [string] $SubscriptionId, [Parameter(Mandatory = $true)] [string] $SelfSignedCertPlainPasswd, [Parameter(Mandatory = $false)] [int] $SelfSignedCertNoOfMonthsUntilExpired = 12 ) # Helper functions function CreateAutomationCertificateAsset { [CmdletBinding()] param ( [Parameter()] [string] $ResourceGroup, [Parameter()] [string] $AutomationAccountName, [Parameter()] [string] $CertifcateAssetName, [Parameter()] [string] $CertPath, [Parameter()] [string] $CertPlainPasswd, [Parameter()] [bool] $Exportable ) [securestring] $CertPassword = ConvertTo-SecureString $CertPlainPasswd -AsPlainText -Force Remove-AzAutomationCertificate -ResourceGroupName $ResourceGroup ` -AutomationAccountName $AutomationAccountName ` -Name $CertifcateAssetName ` -ErrorAction SilentlyContinue New-AzAutomationCertificate -ResourceGroupName $ResourceGroup ` -AutomationAccountName $AutomationAccountName ` -Path $CertPath ` -Name $CertifcateAssetName ` -Password $CertPassword ` …