AzureAutomationAuthoringToolkit.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<#
    Learn more here: http://aka.ms/azureautomationauthoringtoolkit
#>


Copy-ConfigFile

if ($PSIse) {
    $null = $PSIse.CurrentPowerShellTab.VerticalAddOnTools.Add('Azure Automation ISE add-on', [AutomationISE.AutomationISEControl], $True)
}

<#
    .SYNOPSIS
        Get a credential asset from Azure Automation.
        Part of the Azure Automation Authoring Toolkit to help author runbooks locally.
#>

workflow Get-AutomationPSCredential {
   [CmdletBinding(HelpUri='http://aka.ms/azureautomationauthoringtoolkit')]
   [OutputType([PSCredential])]

    param(
        [Parameter(Mandatory=$True)]
        [string] $Name
    )

    Write-Verbose "AzureAutomationAuthoringToolkit: Looking for local credential asset with name '$Name'"

    $AssetValue = Get-AzureAutomationAuthoringToolkitLocalAsset -Type PSCredential -Name $Name

    if($AssetValue) {
        Write-Verbose "AzureAutomationAuthoringToolkit: Converting '$Name' asset value to a proper PSCredential"
        
        $SecurePassword = $AssetValue.Password | ConvertTo-SecureString -AsPlainText -Force
        $Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $AssetValue.Username, $SecurePassword

        Write-Output $Cred
    }
}