gregt8

joined 1 year ago
[–] gregt8 3 points 1 year ago (1 children)

Makes sense. I found an environment variable that detects whether the process is running in Azure Automation, i.e. it's running in Azure Automation if the variable is defined:

Get-ChildItem -Path env:AZUREPS_HOST_ENVIRONMENT

This helped me provide some conditional control on when to use the managed identity and when to use my interactive credentials.

All the while I'm figuring out that using the Azure Automation plugin with VS Code is only useful for publishing code in runbooks; the extension doesn't provide an easy way to manage custom modules. And with the code I'm writing, I'm quickly finding that it won't be efficient to include everything in runbook files. So I'm now heading down the path of using a pipeline to publish my custom module to Azure Automation, then calling that module with a lightweight runbook.

Appreciate the guidance!

[–] gregt8 2 points 1 year ago (1 children)

My challenge is that I'm used to developing scripts locally with an account that has privileged access. The development time w/ debugging is fast, as the account has immediate access. With Azure Automation, I have to wait for a cloud job to complete, and sometimes this takes a minute or two. That's too long for me to execute and wait for the results.

I would rather develop locally using a privileged account and then push to Azure Automation when I'm confident that my script logic is executing as expected.

I think I found a way around the issue. In my script logic I can test for the PowerShell profile path. In Azure Automation, the profile path references 'ContainerUser'. When running locally my profile path references my local directory. If the profile path references ContainerUser then I can specify to use the user-managed identity; otherwise, I'll use my interactive credentials, e.g. a PowerShell session that I have previously established locally with Exchange Online.

 

I've always developed and ran scripts locally through VS Code. I'm just getting started with Azure Automation and am not a fan of waiting for the job to complete before seeing my results. In fact, it's very frustrating. I'd rather develop and test my script locally first before running it in Azure Automation.

I'm using a user-managed identity to run scripts against Exchange Online. VS Code has an Azure Automation plugin that provides an option to run script locally, but the script bombs out when attempting to use the user-managed identity, as the user-managed identity may only be run in Azure.

For those of you who use Azure Automation, I can't imagine that you develop significant portions of the script and wait for automation jobs to complete each time to verify changes.

How do you develop locally? Do you use an app registration w/ client secret in key vault and call that from your local machine? Do you have a process for developing locally for scripts that specify managed identities?

Thanks everyone!

[–] gregt8 3 points 1 year ago

Nice! Been waiting for this. Thx for the heads up.

[–] gregt8 2 points 1 year ago

I love how James documents his code. He tells a story with his comments:

        #region Create Color Scheme Object
        $newScheme =
            if ($iTermThemeExists)
            {
                # If the theme exists, let them customize it.
                foreach ($k in $PSBoundParameters.Keys) {
                                                    # Any supplied parameter
                    if ($k -ne 'Name' -and          # except name
                        $iTermThemeExists.$k        # that exists in the theme
                    ) {
                        $iTermThemeExists.$k =      # will be overwritten
                            $PSBoundParameters[$k]  # with the supplied parameter.
                    }
                }
                $iTermThemeExists
[–] gregt8 3 points 1 year ago

Nice, thank you! Just what I was looking for. This guy has an incredible GitHub page.

 

I've been writing PowerShell code for almost 10 years now, and I love it when I come across someone who uses interesting techniques and patterns that I haven't seen before.

Do any of you have a list of users in the community from which you've taken inspiration in your own code? Who are they? I'd like to follow them :-)