Tag: Scripts

Create Custom Script Extension for Windows - Azure Arc

How to Run Custom Scripts on Azure Arc Enabled Servers

With the latest update for Azure Arc for Servers, you are now able to deploy and use extensions with your Azure Arc enabled servers. With the Custom Script extension, you can run scripts on Azure Arc enabled servers and works similar to the custom script extension for Azure virtual machines (VMs). There is an extension for Windows and Linux servers, which is a tool that can be used to launch and execute machine customization tasks post configuration automatically.

When this Extension is added to an Azure Arc machine, it can download PowerShell and shell scripts and files from Azure storage and launch a script on the machine, which in turn can download additional software components. Custom Script Extension for Linux and Windows – Azure Arc tasks can also be automated using the Azure PowerShell cmdlets and Azure Cross-Platform Command-Line Interface (Azure CLI).

Introducing Azure Arc
For customers who want to simplify complex and distributed environments across on-premises, edge and multicloud, Azure Arc enables deployment of Azure services anywhere and extends Azure management to any infrastructure.
Learn more about Azure Arc here.

How to run Custom Scripts on Azure Arc enabled servers

To run a custom script on an Azure Arc enabled server, you can simply deploy the Custom Script Extension. You open the server you want to run the custom script in the Azure Arc server overview. Navigate to Extensions and click on Add, and select the Custom Script Extension for Windows – Azure Arc or on Linux the Custom Script Extension for Linux – Azure Arc.

Add Custom Script Extension

Add Custom Script Extension

Now you can select the PowerShell or shell script you want to run on that machine, as well as adding some optional arguments for that script.

Create Custom Script Extension for Windows - Azure Arc

Create Custom Script Extension for Windows – Azure Arc

After that, it will take a couple of minutes to run the script on the machine.

Conclusion

The Custom Script Extensions for Linux and Windows can be used to launch and execute machine customization tasks post configuration automatically.

You can learn more about how Azure Arc provides you with cloud-native management technologies for your hybrid cloud environment here, and you can find the documentation for Azure Arc enabled servers on Microsoft Docs.

If you have any questions or comments, feel free to leave a comment below.



Run Azure PowerShell in a Docker Container Image

Run Azure PowerShell in a Docker Container

Yesterday, the Azure PowerShell team announced the Azure PowerShell Docker Container images. In this post, I want to quickly highlight that announcement and show you how you can download, pull, and run Azure PowerShell in a Docker container image from Microsoft.

But first, let’s talk about why you would want to run an Azure PowerShell in a Docker container. Azure is continuously evolving, and the Azure PowerShell team releases a new version of the Azure PowerShell modules every three weeks. This makes it challenging to maintain a production or development environment up to date and ensuring the smooth execution of scripts. With the Azure PowerShell docker container image, you can quickly run scripts against a specific version of Azure PowerShell.

The team highlights the current scenarios:

  • On the same machine, you can run scripts that are using a different version of Az with no conflicts.
  • You can test a script against a different version of Az with no risks.
  • You can run the latest container image interactively.


How to create a Powershell v2 Module

Powershell Header

If you need some functions a lot in different scripts you create maybe external function files. This is a good way to clean up your code. To get this functions running in your mainscript.ps1 you can call this other file “dotsourced”:

. C:\PSscript\output\sayhello.ps1

If you have more than one external function you have to call each file:

. C:\PSscript\Modules\Output\sayhello.ps1
. C:\PSscript\Modules\Output\saygoodday.ps1
. C:\PSscript\Modules\Output\saybye.ps1

In Powershell v2 you can create your own modules, which you can call by:

Import-Module C:\PSscript\Modules\Output

Now how can you create this output module?

  • First you create a directory for the all modules, called Modules
  • Secound you create a directory for the Output module, called Output
  • Than copy all of your Powershell Scripts (.ps1 files) in to this folder
  • Now create a file called Output.psm1. Its important that this file has the same name as the folder
  • In this file write the following code (for each file in this folder):
    . ./Modules/Output/sayhello.ps1
    . ./Modules//Output/saygoodday.ps1
    . ./Modules//Output/saybye.ps1

Now you can use the Import-Module to import your own module called output.

There are a lot of other things you can use to make everything a little bit easier, like system variables for the module and script paths.