What Modules Are Available In Azure Functions PowerShell

What Modules Are Available In Azure Functions PowerShell

In this Azure tutorial, we will discuss What Modules Are Available In Azure Functions PowerShell. Along with this, we will also discuss a few other topics like Default PowerShell modules Azure Functions, Create Azure Function App Using PowerShell, Create Azure Function App Using PowerShell Visual Studio Code, Create Azure Function App Using PowerShell In Azure Portal. We will also discuss Azure Functions Timer Trigger PowerShell, Installing PowerShell Modules By Using Install-Module Is Not Allowed, How To Add Custom Modules In The Azure Functions App, Add Custom Modules In The Azure Functions App using Kudu, How To Load Custom Modules From The Azure Functions App.

What Modules Are Available In Azure Functions PowerShell? Now Azure Function supports different modules. There are many PowerShell modules that are supported in case of Azure Functions, Below are few among them

  • AppLocker
  • Appx
  • AppBackgroundTask
  • Az.Accounts
  • Az.Advisor
  • Az.Compute
  • AzureAD

We will discuss all the lists of module below in detail with the version.

What Modules Are Available In Azure Functions PowerShell

Like you can create the Azure Functions using the C#, Javascript, java, etc. Same way, you can create the Azure Functions using the PowerShell. You can build your PowerShell script based on your business requirement and run as part of your Azure Functions app.

Azure Function with PowerShell executes the PowerShell script when it triggers. Same way like the Azure Function in other languages, it has also the function.json file that actually defines the behavior of the Azure function like the input and out parameters for the function and how the Azure function triggered.

There are different PowerShell modules are supported in the case of Azure Functions. Below are the lists of some key modules with the version details.

Module NameVersion
AppLocker2.0.0.0
Appx2.0.1.0
AppBackgroundTask1.0.0.0
AppvClient1.0.0.0
AssignedAccess1.0.0.0
Az.Accounts1.9.2 and 1.7.5
Az.Advisor1.1.1
Az.Aks1.0.3 and 1.2.0
Az.AnalysisServices1.1.2 and 1.1.4
Az.ApiManagement2.1.0 and 1.4.1
Az.ApplicationInsights1.0.3 and 1.1.0
Az.Automation1.3.6 and 1.3.7
Az.Batch2.0.2 and 3.1.0
Az.Billing1.0.2 and 1.0.3
Az.Cdn1.4.3
Az.CognitiveServices1.3.0 and 1.5.1
Az.Compute3.7.0 and 4.2.1
Az.ContainerInstance1.0.3
Az.ContainerRegistry1.1.1
Az.DataBoxEdge1.1.0
Az.DataFactory1.7.0 and 1.9.0
Az.DataLakeAnalytics1.0.2
Az.DataShare1.0.0
Az.DeploymentManager1.1.0
Az.DesktopVirtualization1.0.0
Az.DevTestLabs1.0.2
Az.Dns1.1.2
Az.EventGrid1.2.3 and 1.3.0
Az.EventHub1.5.0 and 1.4.3
Az.FrontDoor1.4.0 and 1.6.1
Az.Functions1.0.1
Az.HDInsight3.1.0 and 3.4.0
Az.HealthcareApis1.1.0 and 1.0.1
Az.IotHub2.5.0 and 2.4.0
Az.KeyVault2.0.0 and 1.6.0
Az.LogicApp1.3.2
Az.MachineLearning1.1.3
Az.Maintenance1.0.0
Az.ManagedServices1.0.2
Az.MarketplaceOrdering1.0.2
Az.Media1.1.1
Az.Monitor1.7.0 and 2.0.2
Az.Network2.5.0 and 3.3.0
Az.NotificationHubs1.1.1
Az.OperationalInsights1.3.4 and 2.3.0
Az.PolicyInsights1.3.1 and 1.3.0
Az.PowerBIEmbedded1.1.2 and 1.1.1
Az.PrivateDns1.0.3 and 1.0.2
Az.RecoveryServices2.11.1 and 2.8.0
Az.RedisCache1.2.1
Az.Relay1.0.3
Az.Resources 1.13.0 and 2.4.0
Az.ServiceBus1.4.1
Az.ServiceFabric2.1.0 and 2.0.2
Az.SignalR1.1.1
Az.Sql2.9.1 and 2.6.0
Az.SqlVirtualMachine1.1.0
Az.Storage2.4.0 and 1.14.0
Az.StorageSync1.3.0 and 1.2.3
Az.StreamAnalytics1.0.1
Az.Support1.0.0
Az.TrafficManager1.0.4 and 1.0.3
Az.Websites1.11.0 and 1.8.0
AzTable2.0.3
AzureAD2.0.2.106
AzureADPreview2.0.2.105 and 2.0.2.102
BitLocker1.0.0.0
BitsTransfer2.0.0.0
BranchCache1.0.0.0
CimCmdlets1.0.0.0
ConfigCI1.0
ConfigDefender1.0
Defender1.0
DeliveryOptimization1.0.2.0
DirectAccessClientComponents1.0.0.0
Dism3.0
DnsClient1.0.0.0
EventTracingManagement1.0.0.0
International2.0.0.0
iSCSI1.0.0.0
ISE1.0.0.0
Microsoft.Online.SharePoint.PowerShell16.0.20017.0
Microsoft.PowerShell.Archive1.0.1.0
Microsoft.PowerShell.Diagnostics3.0.0.0
Microsoft.PowerShell.Host3.0.0.0
Microsoft.PowerShell.LocalAccounts1.0.0.0
Microsoft.PowerShell.Management3.1.0.0
Microsoft.PowerShell.ODataUtils1.0
Microsoft.PowerShell.Operation.Validation1.0.1
Microsoft.PowerShell.Security3.0.0.0
Microsoft.PowerShell.Utility3.1.0.0
Microsoft.WSMan.Management3.0.0.0
MMAgent1.0
MsDtc1.0.0.0
MSOnline1.1.183.57
MSOnlineBackup2.0.0.0
NetAdapter2.0.0.0
NetConnection1.0.0.0
NetEventPacketCapture1.0.0.0
NetLbfo2.0.0.0
NetNat1.0.0.0
NetQos2.0.0.0
NetSecurity2.0.0.0
NetSwitchTeam1.0.0.0
NetTCPIP1.0.0.0
NetworkConnectivityStatus1.0.0.0
NetworkSwitchManager1.0.0.0
NetworkTransition1.0.0.0
PackageManagement1.4.7, 1.0.0.1 and 1.0.0.0
PcsvDevice1.0.0.0
PersistentMemory1.0.0.0
Pester1.0.0.0
PnpDevice1.0.0.0
PowerShellGet1.0.0.1
PrintManagement1.1
ProcessMitigations1.0.11
Provisioning3.0
PSDesiredStateConfiguration1.1
PSDiagnostics1.0.0.0
PSReadline2.0.0
PSScheduledJob1.1.0.0
PSWorkflow2.0.0.0
PSWorkflowUtility1.0.0.0
ScheduledTasks1.0.0.0
SecureBoot2.0.0.0
SharePointPnPPowerShellOnline3.21.2005.2
SmbShare2.0.0.0
SmbWitness2.0.0.0
SQLASCMDLETS1.0
SQLPS1.0
StartLayout1.0.0.0
Storage2.0.0.0
StorageBusCache1.0.0.0
TLS2.0.0.0
TroubleshootingPack1.0.0.0
TrustedPlatformModule2.0.0.0
VpnClient2.0.0.0
WindowsSearch1.0.0.0
WindowsUpdate1.0.0.0
WindowsUpdateProvider1.0.0.2

Default PowerShell modules Azure Functions

You can always check the latest versions of the PowerShell module supported in the case of Azure functions using the below PowerShell script. If you are already using the Visual Studio Code for your Azure PowerShell function development. In Visual studio code itself, you can able to check the different PowerShell modules along with the versions for the Azure Function.

Write-Output ‘Azure Function PowerShell Module’

$modules = Get-Module -ListAvailable | Select-Object Name, Version | Sort-Object -Property Name | Out-String

Write-output `n$modules

You can open a new terminal in the Visual Studio Code IDE, and run paste the above PowerShell script to get the list of PowerShell modules available for your Azure PowerShell function. As of now, these are the modules that are supported or available for the Azure Functions.

What Modules Are Available In Azure Functions PowerShell

Installing PowerShell Modules By Using Install-Module Is Not Allowed

One important thing to note down here is you cannot install PowerShell modules by using install-module directly in case of Azure PowerShell functions. Meaning if you will try installing any other modules that are not part of the default modules, than it will not allow you to install the modules, it will show you the error message ” Administrator rights are required to install modules “.

Below is the exact error message what i got

install-module : Administrator rights are required to install modules in ‘C:\Program Files\WindowsPowerShell\Modules’. Log on to the
computer with an account that has Administrator rights, and then try again, or install
‘C:\Users\Bijay\Documents\WindowsPowerShell\Modules’ by adding “-Scope CurrentUser” to your command. You can also try running the Windows
PowerShell session with elevated rights (Run as Administrator).
At line:1 char:1

  • install-module azurerm
  • ~~~~~~
    • CategoryInfo : InvalidArgument: (:) [Install-Module], ArgumentException
    • FullyQualifiedErrorId : InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser,Install-Module

You can see it here

Administrator rights are required to install modules

Since the install-module points to the PowerShell environment directory directly and we don’t have access to that so we are getting this error message ” Administrator rights are required to install modules ” .

How To Add Custom Modules In The Azure Functions App

You can add the custom modules to your Azure Functions App using the FTP. So basically what we need to do is, We will have to configure one service account using the Azure Portal that will have access to the Azure Function App FTP. Now from the FTP we can able to add the the Custom modules to the Azure Functions App in the path \Site\wwwroot\[Functionname].

Add Custom Modules In The Azure Functions App using Kudu

Another option to use external PowerShell Modules inside of you Azure Function App is to use

Advanced tools (Kudu) for this purpose. This is one of the best option to use in this case. Let’s follow the below steps

Navigate to your Azure Function app that you have created to use with PowerShell. Click on the Advanced Tools link under the Development Tools section.

Import PowerShell Module or Package into your Azure Function App

Now click on the Go button on the Advanced Tools window.

How To Add Custom Modules In The Azure Functions App

Select the CMD option from the Debug console DropDown from the top navigation window.

Add Custom Modules In The Azure Functions App

Navigate to the subfolder site/wwwroot/{yourFunctionName}. You can able to see there that two default files run.ps1 and function.json

Click on the Home Button –> Site –> wwroot –> Click on your Function Name

How To Add Custom Modules In The Azure Functions App using Kudu

Now click on the + button –> NewFolder and create a folder with the module name like below

Custom Modules In The Azure Functions App
How To Load Custom Modules From The Azure Functions App

Now you can simply drag and drop the files from your local path to this folder

How To Load Custom Modules From The Azure Functions App using Kudu

Now copy the complete path from the CMD window and keep it as we need to add that in our Import statement

How To Load Custom Modules From The Azure Functions App Kudu

For me, the path is D:\home\site\wwwroot\MyHttpPowerShellFunction\azurerm

Now you need to import the powershell module in the Run.ps1 file like below

Import-Module “D:\home\site\wwwroot\MyHttpPowerShellFunction\azurerm\AzureRM.AnalysisServices.psd1”

This is one of the best option to Add Custom Modules In The Azure Functions App.

How To Load Custom Modules From The Azure Functions App

Once you upload the Custom Module in the Azure Functions App, then import the custom module in the Run. ps1 file on the Function windows as shown above. The import statement will be like below

Import-Module home\Site\wwwroot\MyHTTPPowerShellFunction\[YourModuleFolderName]\filename.psd1

Create Azure Function App Using PowerShell

We can create the Azure Function App using Powershell in the Azure PowerShell as well as we can develop our Azure Function using PowerShell in the Visual Studio Code IDE. Well, Let’s discuss here How to Create Azure Function App using PowerShell in Visual Studio Code IDE. Follow the below steps

The most important thing, Before we start the actual development, You can set up your Environment and install the Prerequisites needed, If you are creating the Azure Function for the First time using the Visual Studio Code IDE.

Create Azure Function App Using PowerShell Visual Studio Code

Assuming you have everything ready to start the Azure Function development activities, Open the Visual Studio Code IDE.

Now from the left side, click on the Azure button and then click on the Create New Project icon from the top as highlighted below.

Create Azure Function App Using PowerShell

The next step is, Browse a location for your Azure Function project where you want to store the project in your local machine. You can click on the Browse button to select your preferred location for the Project.

Create Azure Function App Using PowerShell in Visual Studio Code

Now the next step is very important, Make sure to choose the language as PowerShell here.

Create Azure Function App Using PowerShell in Visual Studio Code IDE

Now the time to choose the trigger for your Azure function. Choose the HTTP trigger as your Azure function trigger. Here you can also choose the trigger as per your business requirement.

How to Create Azure Function App Using PowerShell

Provide the name for your PowerShell Function App

How to Create Azure Function App Using PowerShell in VS Code

Now, you can choose the Authorization level as Anonymous, You can choose any of this based on your business requirement.

Create Azure Function App PowerShell

You can able to see the Azure PowerShell Function project created successfully with out any issue.

Create Azure Function App VS Code PowerShell

The Default Azure Functions PowerShell script

Once the Project got created successfully, It creates the default PowerShell Script file run.ps1 and this is the file which contains your actual Azure function code. Along with this file, it also creates one more JSON file named as the Function.JSON file that contains the main configuration or settings for your Azure function. Along with this it also contains the trigger and bindings for your Azure functions.

Now, If I will open my run.ps1 file, below is the code that it contains

using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."

# Interact with query parameters or the body of the request.
$name = $Request.Query.Name
if (-not $name) {
    $name = $Request.Body.Name
}

if ($name) {
    $status = [HttpStatusCode]::OK
    $body = "Hello $name"
}
else {
    $status = [HttpStatusCode]::BadRequest
    $body = "Please pass a name on the query string or in the request body."
}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = $status
    Body = $body
})

You can see below

Modules Available In Azure Functions PowerShell

Now if I will open the Function.JSON file, you can find the below code present there. You can able to see this file contains all the configurations for the Azure Function

{
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "Request",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "Response"
    }
  ]
}

you can find the same code here

Create Azure Function App in PowerShell

Now let’s run the Azure PowerShell function to check if it is working fine with out any issue. You can see below it executed successfully and we got the Azure function URL.

http://localhost:7071/api/MyDemoPowerShell

azure function run powershell script

Now we got the function URL, So let’s see if it is working fine or not. So to test that you can paste the Azure Function URL in any of your favorite Browser. You can see it is prompting me to pass a name on the query string or in the request body and this is the expected behavior.

azure function app powershell reference

Now i provided a name value in the query string and now you can able to see we got the expected output. So the Azure PowerShell function is working as expected.

azure functions powershell modules

Create Azure Function App Using PowerShell In Azure Portal

Above, we discussed how to create Azure Functions using PowerShell Visual Studio Code. We can also able to create Azure Function App using PowerShell in Azure Portal. Follow the below steps to create the Azure PowerShell Function.

Login to the Azure Portal

Once logged in to the Azure Portal, search for the Azure Functions App and click on the search result Function App as highlighted below.

Create Azure Function App Using PowerShell In Azure Portal

Click on the + Add button to create the Azure Function App on the Function App page.

Create Azure Function App with PowerShell In Azure Portal

Provide the below details for the Basics tag on the Create Function App window

  1. You have to choose your valid Subscription.
  2. The next option is, you need to choose your Existing Resource Group if you have a resource group already and in case, if you don’t have any existing resource group, click on the Create new link to create a new resource group.
  3.  You need to enter an unique name for your Azure Function App for the Function App name option.
  4. Here, For the Publish option, you can choose the Code option.
  5. Since we will have to create the Azure Function App in PowerShell so you can choose the PowerShell Core for Runtime stack option.
  6. It will take the latest version for the Version option . Here it is 7.0.
  7. Finally, You need to select the Region for your Function App.
How to Create Azure Function App Using PowerShell In Azure Portal

Now click on the Next : Hosting > button to navigate to the Hosting tab.

Provide the below option details for the Hosting tab

  • Storage account: Choose your existing storage account if you have or you can click on the Create new link to create a new storage account.
  • Operating system: You choose the operating system as Windows.
  • Plan type: Choose your Function App plan type.
How to Create Azure Function App with PowerShell In Azure Portal

Keep the other tab value as it is and now click on the Review + Create button

Well, the next step is click on the Create button on the next window to create the Azure PowerShell Function App.

Now, you can see the deployment is completed successfully and now click on the Go to resource button to see the Function App that we created just now.

Create Azure Function App in PowerShell using Azure Portal

So now our Azure PowerShell Function App is ready. So the next what we need is, we need to create an Azure Functions. So to create the Azure PowerShell Function follow the below steps

Click on the Functions link from the left navigation on the Function App page and then click on the + Add button to create the new Azure PowerShell Function.

Create Azure Functions using PowerShell in Azure Portal

Now as we already know this, A trigger is must for the Azure function. So select the HTTP trigger from the below window

Create Azure Functions using PowerShell Azure Portal

On the next window, Provide an unique name for the Azure Function and then choose the Authorization level as Anonymous and finally, click on the Create Function button to create the Azure Function.

Create Azure Functions using PowerShell from Azure Portal

Now you can able to see the Azure Function created successfully

How to create Azure Functions using PowerShell in Azure Portal

You can see the function code as below. Now to make sure that the function is working fine, we can check that by clicking on the Code + Test link on the Function page and then click on the Test/Run from the top.

How to create Azure Functions using PowerShell from Azure Portal

Provide the input values from the below window, Choose the HTTP method and provide the name value in the Body and then click on the Run Button.

How to create Azure Functions PowerShell from Azure Portal

We got the expected output with the proper Response code i.e 200 OK as below

How to create Azure Functions  PowerShell in Azure Portal

Azure Functions Timer Trigger PowerShell

Above, we discussed How to create HTTP triggered Azure Function using the Azure Portal. Now we will discuss How to create An Azure Timer Trigger Function using PowerShell in Azure Portal. Follow the below steps to create the Azure Timer Trigger Function.

You can follow the same steps as mentioned above till you create the Azure Function App. Once your Function app is Deployed successfully, you can able to see the below screen. Click on the Go to resource button to open the Azure Function ap created.

Azure Functions Timer Trigger PowerShell

Now our function app is ready, You can see the below screen shot

Azure Functions Timer Trigger using PowerShell

So the now the time to create the Azure timer triggered function since our Function app is ready now. To create the function follow the below steps

You need to click on the Functions link from the left navigation on the Function App page and then the next step is to click on the + Add button to create the new Azure timer triggered function.

How to create Azure timer triggered function

Now this is a very important step, make sure to select the Timer trigger as the template on the New Function window.

How to create Azure timer triggered function AzurePortal

Provide an unique name for your timer triggered function and then mention a Schedule based on your business need. You can click on the info icon on the format to mention for the Schedule option. Finally, click on the Create Function button to create the timer triggered PowerShell Azure function.

How to create Azure timer triggered function using AzurePortal

Now you can able to see the Azure PowerShell Timer Triggered Functions created successfully with out any issue. Refer to the below screenshot.

How to create Azure Functions Timer Trigger PowerShell

Below is the code for the Run.ps1 file

# Input bindings are passed in via param block.
param($Timer)

# Get the current universal time in the default string format.
$currentUTCtime = (Get-Date).ToUniversalTime()

# The 'IsPastDue' property is 'true' when the current function invocation is later than scheduled.
if ($Timer.IsPastDue) {
    Write-Host "PowerShell timer is running late!"
}

# Write an information log with the current time.
Write-Host "PowerShell timer trigger function ran! TIME: $currentUTCtime"
How to create Azure Poweshell Timer Trigger Function

This is the code for the function.json file as mentioned below

0 */5 * * * *” is known as the CRON expression. For example below are few CRON expression and their time details.You can decide based on your business

The format of the CRON expressions in Azure is, 

{second} {minute} {hour} {day} {month} {day of the week}

CRON ExpressionTime Details
*/1 * * * * *Function will execute Every second
0 * * * * *Function will execute Every minute
0 */3 * * * *Function will execute Every 3 minutes
0 0 * * * *Function will execute Every hour
0 0 0 * * *Function will execute Every day
 0 0 0 * * 1-5Function will execute Every workday (Monday to Friday)
{
  "bindings": [
    {
      "name": "Timer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */5 * * * *"
    }
  ]
}
Create Azure PowerShell Timer Trigger Function

Now click on the Test/Run and then on the Run button to check if the Function is executed successfully. As per our CRON expression0 */5 * * * *” what we have mentioned above, so it means the function will execute each 5 minutes duration. You can able to see it is working as expected. You can refer to the below screen shot.

Azure Functions Timer Trigger PowerShell in Azure

You may also like following the below Articles

Wrapping Up

Well, in this article, we discussed, What Modules Are Available In Azure Functions PowerShell, Default PowerShell modules Azure Functions, Create Azure Function App Using PowerShell, Create Azure Function App Using PowerShell Visual Studio Code, Create Azure Function App Using PowerShell In Azure Portal, Azure Functions Timer Trigger PowerShell, Installing PowerShell Modules By Using Install-Module Is Not Allowed, How To Add Custom Modules In The Azure Functions App, Add Custom Modules In The Azure Functions App using Kudu, How To Load Custom Modules From The Azure Functions App. Hope you enjoyed this Article !!!.