6 PowerShell 6 to 7 Migration Guide
Stefanus Hinardi редактировал(а) эту страницу 2021-03-29 17:56:00 -07:00

As we are quickly approaching end of life for PowerShell 6, we encourage developers to upgrade their PowerShell 6 to PowerShell 7, in order to get full support for PowerShell.

For more information on PowerShell lifecycle timeline, please refer to this page.

Note that Azure Functions will maintain existing PowerShell 6 Functions Apps

Developing PowerShell 7 function apps locally using VS Code

  1. Open you Azure Functions App using VS Code
  2. Navigate to "local.setting.json"
  3. Add the property "FUNCTIONS_WORKER_RUNTIME_VERSION" and set the value to "~7". The local.setting.json file should look like:
    {
      "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "",
        "FUNCTIONS_WORKER_RUNTIME": "powershell",
        "FUNCTIONS_WORKER_RUNTIME_VERSION" : "~7"
      }
    }
    

Upgrading PowerShell functions from 6 to 7

Using Azure Portal

  1. Login to Azure Portal

  2. Navigate To Azure Functions Portal

  3. On the left Panel, click on Configuration Settings Panel

  4. Click on Function Runtime Settings blade, verify that the Azure function runtime is set to ~3, if not, set it to ~3 and click Save Runtime Version

  5. Click on General Settings blade, change the PowerShell Version Setting to 7.0. and click Save PowerShell Version

Using Azure PowerShell

  1. To check the verify that your function app is running on Azure function runtime v3, execute
$SubId = …
$ResourceGroupName = ...
$AppName = ...

Get-AzResource -ResourceId "/subscriptions/$SubId/resourceGroups/$ResourceGroupName/providers/Microsoft.Web/sites/$AppName/config/appsettings" 
  1. If the app is not running on Azure Functions v3 runtime, execute the following command to upgrade:
Set-AzResource -ResourceId "/subscriptions/$SubId/resourceGroups/$ResourceGroupName/providers/Microsoft.Web/sites/$AppName/config/appsettings" -UsePatchSemantics -Properties @{  FUNCTIONS_EXTENSION_VERSION  = '~3' } -Force
  1. Once the Azure Function runtime is upgraded to v3. execute the command bellow to migrate PowerShell 6 to PowerShell 7:
Set-AzResource -ResourceId "/subscriptions/$SubId/resourceGroups/$ResourceGroupName/providers/Microsoft.Web/sites/$AppName/config/web" -UsePatchSemantics -Properties @{ powerShellVersion = '~7' } -Force

Creating Azure Functions using PowerShell 7 in ARM template

In your ARM template, please specify these settings:


        "siteConfig": {
            "appSettings": [
                ...
                {
                    "name": "FUNCTIONS_EXTENSION_VERSION",
                    "value": "~3"
                },
                {
                    "name": "FUNCTION_WORKER_RUNTIME",
                    "value": "powershell"
                },
                ...
            ],
            ...
            "powerShellVersion": ~7,
            ...
        }