No need to use Install-Module in this case, currently, when you create the powershell function in the portal, it will install the Az module for you by default via the Dependency management feature.
You could check the App files blade in the portal to make sure your function app was configured correctly, if not, change them like below.
host.json
{
"version": "2.0",
"managedDependency": {
"Enabled": true
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
}
}
requirements.psd1
@{
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
'Az' = '5.*'
}
profile.ps1
if ($env:MSI_SECRET) {
Disable-AzContextAutosave -Scope Process | Out-Null
Connect-AzAccount -Identity
}
With the settings above, the function app will install Az module for you automatically and login Az module with MSI(managed identity) of your function app(command in profile.ps1 did it), it is convenient.
To use Az commands in the function, you just need to enable the MSI for your function app and assign the RBAC role to your MSI(depend on specific case, e.g. if you want to list all the web apps in your subscription/resource group, you need give the role like Reader to your MSI at the subscription/resource group scope).

Then in your function code, just use the Az command directly without anything else.
Sample:
$a = Get-AzWebApp -ResourceGroupName joyRG
Write-Host $a.Name
