mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
個人BLOG
it developer
  1. Main page
  2. M365
  3. Main content

Set up Azure Automation Run As account

2020-12-20 142hotness 0likes 0comments

# 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 `
        -Exportable:$Exportable
}

function CreateAutomationConnectionAsset {

Tag: Nothing
Last updated:2020-12-20

mikebai

This person is a lazy dog and has left nothing

Like
< Last article
Next article >

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang